[Gllug] simple file matching

Liam Smit liam.smit at gmail.com
Wed Aug 24 09:43:55 UTC 2005


Hi Neil

> I recently had to match a list of items in one file with that of
> another. The lists were unordered and using diff or comm didn't work
> for me. I don't use perl or python typically so I hit the standard
> bash syntax and summoned:
> 
> for i in `cat file1`; do cat file2 | grep "$i" >> matches; done
> 
> results were okay (a couple of double entries for some reason) but I
> can't help feeling there was a better way to do this (without
> referring to other scripting languages) - esp. if both lists were
> very large.
> 
> How have you unix gurus defeated file/list matching using bash?

That depends very much on exactly what you are tying to achieve as
well as the format of the files.

You might try using <cut> to grab the field that you want to match on
and pipe | the results to <grep>, this should help with the double
entries. Using <sort> on the files before hand might also have made
things easier.


cheers

Liam
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list