Re: grep with multiple and
- From: pk <pk@xxxxxxxxxx>
- Date: Wed, 04 Feb 2009 17:10:55 +0100
On Wednesday 4 February 2009 17:05, marc wrote:
Hello,
Is it possible with grep to find multiple strings in a file ?
i.e. : file foo.txt contains : S1 and S2 and S3 and S4, etc...
I've found with 2 values , but not with several ones.
It's not clear to me what you're asking, however:
grep -e S1 -e S2 -e S3 -e S4 file
will match line containing S1 OR S2 OR S3 OR S4, while
grep 'S1.*S2.*S3.*S4' file
matches lines that contains S1 AND S2 AND S3 AND S4, in that order. If you
want to match for all patterns (AND) in any order, you can either write an
insanely long grep command line, or use awk:
awk '/S1/&&/S2/&&/S3/&&/S4/' file
.
- Follow-Ups:
- Re: grep with multiple and
- From: marc
- Re: grep with multiple and
- References:
- grep with multiple and
- From: marc
- grep with multiple and
- Prev by Date: grep with multiple and
- Next by Date: Re: grep with multiple and
- Previous by thread: grep with multiple and
- Next by thread: Re: grep with multiple and
- Index(es):
Relevant Pages
|