[英]How do I use zgrep to look for content in archived files matching a given filename pattern?
Suppose I have two tar.gz files假设我有两个 tar.gz 文件
a1.tar.gz
a2.tar.gz
and each archive contains many files, including a file called并且每个存档都包含许多文件,其中包括一个名为
target.txt
How do I search for BLAH
in target.txt
in both of these archives using zgrep without searching all of the other files in each archive?如何寻找
BLAH
在target.txt
均使用zgrep这些档案没有搜索所有其他文件中每个存档?
If I try如果我尝试
zgrep -a BLAH *.tar.gz
then that searches all files in each archive, and if I try然后搜索每个存档中的所有文件,如果我尝试
zgrep --include=target.txt -a BLAH *.tar.gz
then I get然后我得到
zgrep: --include=target.txt: option not supported
You can use zgrep
, however this command will not locate the file you are looking for as it searches the entire tar-formatted file for matches.您可以使用
zgrep
,但是此命令不会定位您要查找的文件,因为它会在整个 tar 格式的文件中搜索匹配项。 This will report which tar file has a match for BLAH
but this does not limit searching tar files containing the file target.txt
.这将报告该tar文件有一个匹配
BLAH
但这并不限制搜索包含文件的tar文件target.txt
。
There is an open source tool called ugrep to search archives (zip, tar, pax, cpio, jar) and tar.gz tarballs.有一个名为ugrep 的开源工具可用于搜索档案(zip、tar、pax、cpio、jar)和 tar.gz tarball。 Use option
-z
and -g target.txt
to search for BLAH
in target.txt
in all of the tar files found recursively:使用选项
-z
和-g target.txt
搜索BLAH
在target.txt
在所有焦油找到的文件递归的:
ugrep -z "BLAH" -g target.txt
To search the working directory only without recursing deeper:只搜索工作目录而不深入递归:
ugrep -z "BLAH" -g target.txt .
Note that option -g
takes a glob.请注意,选项
-g
需要一个 glob。 Use a quoted glob like -g "*.txt"
to match all .txt files.使用像
-g "*.txt"
这样的带引号的 glob 来匹配所有 .txt 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.