Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing files 1

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
US
I have two files. One file has all the servers with my software installed. The other file is a list of all servers that may or may not have one of my servers in the list.

I had considered a diff, but it would simply show me all the differences. What I would like is something like:

Do any of the servers in file A ( my servers ) show up in File B ( all servers )? If they do, tell me.

Sounds simplistic and I'm probably overlooking something, but I've got a mental block.
 
I believe you sort both files, then use comm -3 to see the common files.

eugene
 
Sorry, I should add, that I'm not wanting to do a line by line comparison.

Rather, read in first line of my servers in File A, search File B for that server, match Y/N, echo result, read 2nd line of my server in File A, search File B for that server, match Y/N, echo result, 3rd line...
 
You meen something like:
Code:
grep -f fileA fileB
maby?
or
Code:
grep -vf fileA fileB
to list only those uniq to fileB.

HTH
 
elgrandeperro,

I tried comm and I was getting some strange output, so I tested with list1 which has numbers 1-10 and list2 which only has 2,5,8,10 and I when running comm -1 list1 list2 I get

> comm -1 list1 list2
2
5
8
10

Does comm look at columns??

I'm working on some pseudo code now with a for loop possibly, something like...read in my File A and with each line read, grep that line in File B, if it matches, tell me...
 
Oh brother, I was looking WAAAY past the simple solution. grep -f looks like it will do the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top