Re: Find files matching multiple patterns.
- From: johnb <johnb@xxxxxxx>
- Date: Sat, 18 Apr 2009 18:04:13 GMT
On Thu, 16 Apr 2009 10:19:57 +1000, Ben Finney wrote:
Bruce <anon@xxxxxxxxx> writes:
Hello
I was wondering if there is a better way to find files that contain
text matching multiple patterns than find . | xargs grep pattern1 | cut
-d : - f 1 | uniq | xargs grep pattern2 | cut -d : -f 1 | uniq | ...
etc.
You'd do well to do some more reading of ‘grep(1)’.
A regular expression can have alternation in it:
$ find . | xargs grep '\(pattern1\|pattern2\|pattern3\)' | cut -d :
-f 1 | uniq
Also, you're doing a whole lot of post-processing to get the filenames
out of grep's default output, when GNU grep can do it for you:
$ find . | xargs grep --files-with-matches
'\(pattern1\|pattern2\|pattern3\)'
2 cents,
Add the |sort|uniq -c to see how many times we saw that item in the
output.
JB
--
johnb850@xxxxxxx
.
- References:
- Find files matching multiple patterns.
- From: Bruce
- Re: Find files matching multiple patterns.
- From: Ben Finney
- Find files matching multiple patterns.
- Prev by Date: Re: Directory Delete
- Next by Date: Re: Find files matching multiple patterns.
- Previous by thread: Re: Find files matching multiple patterns.
- Next by thread: Re: Find files matching multiple patterns.
- Index(es):
Relevant Pages
|