If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Reading one variable from one file, checking whether it is existing in another file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-10, 18:05
vineelaregonda vineelaregonda is offline
Registered User
 
Join Date: May 2009
Posts: 43
Reading one variable from one file, checking whether it is existing in another file

Hi,

I have a table from which I can get the list of servers. This I am placing in one file (abc). I have one another file (say "xyz) with the list of servers (this is not from the table I am talking above).

Here I have to get the server names one by one from file "abc" and check whether the same is existing in the file "xyz".

For example :

file "abc" has
---------
PPMPDB
HPRD8
TFRCST
DFPDB
RXPPDB
SBOPDB
UCDP
ALGPDB
SMTP
SRMP
RMANREP
FPRD

file "xyz" has
-------------
PPMPDB
HPRD8
TFRCST
DFPDB
RXPPDB
SBOPDB
UCDP

Here "abc" and "xyz" are not same. wherever it is not matching I have to print msg.

Please let me know how to put this in script.

Regards,
Vineela
Reply With Quote
  #2 (permalink)  
Old 01-11-10, 19:02
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Try the following command and filtering the output.
Code:
diff abc xyz
Reply With Quote
  #3 (permalink)  
Old 01-11-10, 20:42
vineelaregonda vineelaregonda is offline
Registered User
 
Join Date: May 2009
Posts: 43
I can not do that here.

For example:

If the file1 has first two rows as follows

abcd
wxyz

and the file2 has

wxyz
abcd

If i execute "diff" command, i will get the difference like two are not same.
My requirement is, I have to check the word "abcd" in file2 (irrespective of the row number).

Hope my requirement is now clear.
Reply With Quote
  #4 (permalink)  
Old 01-12-10, 08:07
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 626
Code:
while read a
do
grep $a xyz
if [ $? -ne 0 ]
then
echo $a does not exist in xyz
fi
done <abc

Last edited by kitaman; 01-12-10 at 08:28.
Reply With Quote
  #5 (permalink)  
Old 01-12-10, 09:03
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
or even:
Code:
sort abc > sorted_abc
sort xyz > sorted_xyz
diff sorted_abc sorted_xyz
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On