Further understanding the Grep! lol

If I use the grep command for parsing files, does it stop parsing right after it finds the matching pattern or does it continue to parse that document?

grep -l "status" *.xml

Hi,

Could you please give your exact requirement so that we can provide you a better solution/suggestion on same.

Thanks,
R. Singh

1 Like

Of course its going to give list of all the files which matches the criteria in that particular directory...

1 Like

Most implementations of the awk utility will stop reading the current file when a match is found when the -l is given on the command line. (There is no requirement that grep quit reading the file when a match is found, but it is more efficient if it is done that way and most implementations of grep try to be efficient.) Note also that if the data being read is from standard input rather than from a path operand given on the command line, that might be treated differently.

1 Like

Confirmed.
I tested a bunch of grep versions. They all stop reading the current file when invoked with -l and finding a match.

1 Like

From GNU grep manual:

-l, --files-with-matches
       Suppress normal output; instead print the name of each input file from which output would normally have been printed.  The 
scanning will stop on the first match.
1 Like