Linux/Searching compressed archives
Appearance
< Linux
Find out which file within an archive contains a text string:
7z e -so example.7z 2>/dev/stdout |grep -i -a -P "(Extracting|search term)"
The redirection of stderr
to stdout
using 2>/dev/stdout
is necessary since 7z
prints file names to stderr
(prepended by the word "Extracting", hence "(Extracting|search term)"
), but it needs to be in stdout
to be picked up by grep
through the pipe. Optionally, append |less
(read: Wikipedia: less (Unix)).
7z
is used since it apparently supports the widest range of archive formats, more than zgrep
, bzgrep
, and xzgrep
.
If anyone has a better solution, feel free to add it.
If the archive is a TAR wrapped within a format such as GZip, BZip2, or XZip, the following command can be used:
7z e -so example.tar.xz |7z e -si -so -ttar 2>/dev/stdout | [piped commands here]