[sclug] Couple of questions

Paul Vanlint paul at polyzing.com
Sat Oct 25 09:05:34 UTC 2003


> The other problem:
> 2) I have 2 text files each containing a list of files. (say txt1 and
> txt2). All files in txt1 are also in txt2, but there are files in txt2
> that are not in txt1. I want to be able to separate out the files which
> do not appear in both.. What is the best way?
> 

I know a couple have people have given you answers to this, but no one
has mentioned 'comm', which surprised me, so I thought I would mention
it.

Look up the man page for comm, but it basically allows you to filter out
rows which are not in either one of the files, or in both. It does
assume that each file is sorted, so you would need to ensure that first.

There are 3 categories that it splits the data into
1) Rows only found in left file
2) Rows only found in right file
3) Rows found in both files

You can then filter out the corresponding rows by specifying -1, -2 or
-3

For example, to show rows which are only in txt2, you would use:

comm -13 txt1 txt2


I have found this utility useful in the past.

Regards,

Paul.





More information about the Sclug mailing list