How to grep string in tar.gz file with matched filenames?
I got a log file called access.tar.gz, which has 100 text files named: a1, a2, a3, …, a100. I want to search for string "fail" in the access.tar.gz file, WITHOUT creating a temp folder by uncompress the .tar.gz file, and need to know which aX file(s) has "fail" string. How can I get the output like:
a2 <line with "fail" string>
a2 <another line with "fail" string>
a6 <line with "fail" string>
a11 <line with "fail" string>
…
( that is, the matched filenames, with matched lines ).
I can use "zgrep -a fail access.tar.gz" to get all the matched lines, WITHOUT the matched filenames, and I don't see any option in zgrep to show filenames. And I think it's very common users want to know which file has the matched lines.
How can I do it with single line of command(s) to do this without writing a script?
Thanks!
|