I am trying to find XML files containing a particular string. These files are however zipped as .gz. Essentially, I want to search through all of these gz files in the directory without extracting them. Additionally, I would like to get the specific filename which matches the search pattern and not the output itself.
I have managed to get the following command to get me the matching output itself from a piped grep command:
gunzip -c *.xml.gz | grep 'idName="M"'
I would like to get the filenames however. I read somewhere that the -l
flag for grep will return the matching filename, but in this case, it gives me a result saying (standard input)
. I assume this is because I need to be piping the filename from gunzip too, but how do I do that?
Edit: Also adding that I have somewhat partial success by doing
gunzip -vc *.xml.gz | grep 'idName="M"'
but this gives me output like
filename_X: 30% -- replaced with stdout
filename_Y: 50% -- replaced with stdout
filename_Z: complete matching output
I would like to suppress the matching output too in this case, and not show all the non-matching filenames.