For example, to search all the files for lines starting with a number and containing the words "SALE PRICE," you could use:
egrep '^[0-9].*SALE PRICE' `find . -type f -print`./archive/ad.1290: 1.99 a special SALE PRICE ./archive/ad.0191: 2.49 a special SALE PRICE
might not work.
If find finds too many files, egrep's
command-line arguments can
can solve that; it splits long sets of arguments into smaller chunks.
There's a problem with that: if the last "chunk" has just one filename
and the grep command finds a match there, grep won't print
The answer is to add the UNIX "empty file,". It's a filename that's guaranteed never to match but always to leave fgrep with at least two filenames:
find . -type f -print | xargs fgrep '$12.99' /dev/null
Then xargs will run commands like:
fgrep '$12.99' /dev/null ./afile ./bfile ... fgrep '$12.99' /dev/null ./archives/ad.0190 ./archives/ad.0290 ... fgrep '$12.99' /dev/null ./old_sales/ad.1289
That trick is also good when you use a wildcard and only one file might match it. grep won't always print the file's name unless you add /dev/null:
whatever" /dev/null /x/y/z/a*