Re: Find files matching multiple patterns.



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
.



Relevant Pages

  • Re: Data validation, mandatory and restricted field length for excel vbs
    ... Just so one reading this thread gets confused, ... Not quite a Regular Expression parser, yet it offers simple, and fairly readable, parsing syntax, something a Regular Expression statement cannot begin to claim. ... That second link takes you to the noted Excel author John Walkenbach's blog site; what I am particularly proud of with respect to my code posted there is the reaction John posted in this blog article in response to my offering it to him... ... Rick Rothstein ...
    (microsoft.public.excel.programming)
  • Re: IO function in Vb.Net slower than in Vb6.0
    ... returned does not contain the terminating carriage return or line feed. ... before you can apply the RegEx anyway. ... >> Can you please paste the regular expression for this? ... if it is changed to reading one ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Zune installation experience
    ... By which time iPods will probably fly." ... Reading that, I learnt about Micro$oft 'points' only being sold in $5 ... Apple's *real* 99 cents. ...
    (uk.comp.sys.mac)
  • Re: IO function in Vb.Net slower than in Vb6.0
    ... if it is changed to reading one ... This is the Regular Expression: ... Search For RegEx or ... I'll try to "simulate"(wink wink:) a 400mb file and check performance. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: damn and bastards
    ... Cheerios were available in a small box and a larger box - as they usually are. ... Reading the small print on the price tags revealed that the large box was .12 cents per ounce, and the small box was .24 cents. ... And the price labels are on the bottom shelf, about 3" off the floor - and I'm an old geezer with questionable knees. ...
    (rec.outdoors.rv-travel)