How to compare two text files

NoSpaze nospaze at gmail.com
Thu May 6 13:17:38 UTC 2010


Am Donnerstag, den 06.05.2010, 18:27 +0530 schrieb W.H. Kalpa Pathum:
> I've got two text files containing email addresses one at a row. The
> number of rows in one file is different from the number of the other
> file. email addresses in one file is already there in the other file
> (there are some more also). What I want to do is extract the list
> which is not in the other file.
> 
> elaboration
> 
> File A has 100 email addresses and file B has 15 email addresses. 15
> email addresses in file B are already there in file A. I want to
> extract the 85 mails (excluding the 15 from file B) from file A.

First, files must have the same pattern form, and be sorted (I assume
you don't have "bill at ms.com" in file1 and "Bill <bill at ms.com>" in file2)

sorting:
$ sort file1>file1.sort
$ sort file2>file2.sort

Show what file1.sort contains but avoid entries in file2.sort:
$ grep -f file2.sort -v file1.sort

visual differences
$ diff --side-by-side file1.sort file2.sort

Greets!
----------------------------------------------
Rodolfo Alcazar Portillo - nospaze at gmail.com
otbits.blogspot.com / counter.li.org: #367962
----------------------------------------------
> hence the AIX boxen of increasing power [...]
That phrasing reminded me of "Rodents of Unusual Size".
-- Mike and Greg Andrews




More information about the users mailing list