I have very long log files, is it possible to ask grep to only search the first 10 lines?
For folks who find this on Google, I needed to search the first n
lines of multiple files, but to only print the matching filenames. I used
gawk 'FNR>10 {nextfile} /pattern/ { print FILENAME ; nextfile }' filenames
The FNR..nextfile
stops processing a file once 10 lines have been seen. The //..{}
prints the filename and moves on whenever the first match in a given file shows up. To quote the filenames for the benefit of other programs, use
gawk 'FNR>10 {nextfile} /pattern/ { print "\"" FILENAME "\"" ; nextfile }' filenames