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 two files

Status
Not open for further replies.

ianicr

IS-IT--Management
Nov 4, 2003
230
GB
Is there an easy way to compare 2 files and see duplicates between the two of them? I know I can do a grep -f file1 file2 but these are pretty big files and grep takes forever. Is there an easier way?
 
Try:

awk 'BEGIN{
while ((getline < &quot;file1&quot;) > 0) { arr[ $1] = 1}
}
{
if( arr[$1] == 1) print
}' file2


Dickie Bird (:)-)))
 
To see items common in both try out

sort file1 file2 | uniq -d

The sort will take time for large files. Perhaps sorting each first and then using comm on the results is fastest overall.

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top