File find | xargs grep for pattern file

Folks

I've been struggling this with for far too liong now and need your help!

I've been happily using grep for a search of a directory, to list the files which contain a string:

find . -type f -mtime -5 -print | xargs grep -l 'invoiceID=\"12345\"'

Now the list of 'invoiceID' I am looking for is getting huge so I was hoping to list them all in a pattern list.

The string for the files I'm searching through are always in the format invoiceID="12345"

I've created a file Pattern.txt

> cat Pattern.txt
'invoiceID=\"12345\"'
'invoiceID=\"23456\"'
'invoiceID=\"34567\"'

...and three corresponding files

> cat Files*
Value"12" invoiceID="12345" Number"45"
Value"23" invoiceID="23456" Number"56"
Value"34" invoiceID="34567" Number"67"

When I run the following, it doesn't find anything:

find . -type f -mtime -5 -print | xargs grep -l -f Pattern.txt

I've tried numerous other formats, without success.

Any ideas ?!!??

Dave.

change your Pattern.txt to:

invoiceID="12345"
invoiceID="23456"
invoiceID="34567"

Basicly saing, when using pattern file with grep, escaping and quoting isn't necessary.

Perfect - that works a treat!

Is it possible to display alongside the filename, the entry within the Pattern.txt file it's has matched against ?

If you have gnu grep you can use -H instead of -l (might exists on other versions also), which will print the line that matched with the name of file on every line. At least on the AIX I use at work there are all the usual gnu tools, just prefixed with g, eg. ggrep for gnu grep.

However, -H doesn't do exactly what you asked for, since it prints the line from the file that matched instead of the matching pattern from Pattern.txt. However simple patterns like invoiceID='xxxx' are easy to identify from among (hopefully) formatted xml. And I'm just guessing it's xml.