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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing 2 files... 1

Status
Not open for further replies.

InigoMontoya

IS-IT--Management
Jun 18, 2003
51
US
I have a really newbie question...

I need to compare 2 files and output to screen what file1 has that file2 does not.

I think the right way to do this is to place them in 2 separate arrays and do a for loop that compares file1[x] with file2[x] if file2[x] doesn't equal file1[x] then print file1[x].

Is there an easier way? TIA
btw I'm using ksh
 
Sounds like a job for the comm utility

Output lines unique to file1
Code:
comm -23 file1 file2
 
Thanks for all the suggestions. I found comm -23 to work best for my situation. I just had to pipe the two files to sort first.
 
Hi,

First off, it's good to read/give tips to what seem obvious questions. I never heard of 'comm' so I'll have to try that out.

The diff command is useful if expecting nominal changes on a per line basis, otherwise the output can get verbose and not very friendly.

Maybe this is the long way, but I do a double uniq technique, where I get the uniq lines after cat'ing (which it seems you did), then re-cat this output with file1 and unid -d it to see that the uniq lines are specific to file1 only and not across file1 and file2. (Assuming the lines in file1 are uniq to begin with.)

Not elegent, but I hope this concept helps.

Sean aka TimeTraveler




Visit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top