I got a command foo
that output a list of files separated by \n
line.
I am using the below command to filter the results by regex content of the files.
foo | xargs grep -l regex
The problem is that some files are very large and the content that I am searching can be found only at the first 10 lines. How can I tell grep to only process the first 10 lines in order to speed this execution?
head
command-m 1
which stops reading the file after the first match. Doesn't help with big files if the pattern is not found.-l
option stop after the first match anyhow?-m 1
is a good solution, but it only solves half of the problem.