grep question: either of 2 patterns?
Ken Gosier
ken at kg293.net
Tue Sep 2 11:35:48 EDT 2003
Greetings, and I hope this isn't a "D'oh!" question that will make me kick
myself.. :-)
I wanna use grep to match on lines in a file that begin with either of 2
patterns. As far as I understand regex's, I should use ^(...|...) to do
this, as in:
grep ^(fee|fie) junk.txt
Obviously this won't work b/c there are some characters there that are
meaningful to the shell. According to man grep, I should enclose my
pattern in single quotes to get around this:
grep '^(fee|fie)' junk.txt
However, this produces no lines of output (even though I know both
patterns are there). I have tried other alternatives, like
grep ^\(fee\|fie\) junk.txt
with no success. I can get the desired result with:
perl -ne 'print if /^(fee|fie)/' junk.txt
but that's a kludge. It'd be nice to know how to make grep do this. Many
thanks for any help!!! :-)
--
Ken Gosier
ken at kg293.net
ken_gosier at yahoo.com
More information about the Discuss
mailing list