[thelist] grep tip
Liam Delahunty
liam at megaproducts.co.uk
Wed Jul 28 07:33:53 CDT 2004
Having just watched someone write a script to find occurrences of X OR Y
in a file I thought I'd share this tip which would have saved a few minutes.
<tip type="Grep files for regular expressions" author="Liam Delahunty">
Given a list of names in mates.txt
grep bob mates.txt
would find all strings that match bob
grep bob mates.txt | grep ro
would find all lines that have bob & ro, so would get robert, but NOT
just bob on its own
(grep -E = Interpret pattern as an extended regular expression)
grep -E '(bob|bill)' mates.txt
would find all occurrences of bob OR bill
Sometimes you might have a list of search terms formed by another
function. If you have a file of terms called search.txt, which contains
Bob and Bill on new lines.
grep -f search.txt mates.txt
would find all occurrences of Bob OR Bill
</tip>
--
Kind regards, Liam Delahunty, Mega Products Ltd
12 Bury Place, London WC1A 2JL Fax: +44(0)871 224 7891
http://www.megaproducts.co.uk/ Internet Design & Development
http://www.britstream.com/ Internet Design & Development
More information about the thelist
mailing list