我有一个.tar.gz Solaris 格式的文件。 我想从中得到一些行。 我正在使用zipgrep命令,但找不到该行。下面是我正在使用的示例文件和命令。
示例文件:
BD201701.tar.gz
BD201702.tar.gz
BD201703.tar.gz
我正在使用以下命令搜索包含孟加拉国的行。
zipgrep 'bangladesh' BD2017*
但它显示以下错误。
[BD201701.tar.gz]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
zipinfo: cannot find zipfile directory in one of BD201701.tar.gz or
BD201701.tar.gz.zip, and cannot find BD201701.tar.gz.ZIP, period.
/usr/bin/zipgrep: test: argument expected
zipgrep
已经用于处理PKZIP存档文件。在PKZIP存档中,压缩是单独应用于每个包含的文件,因此该过程归结为如下操作序列(不是实际代码!
foreach file in archive:
unzip file to tmpfile
grep tmpfile
压缩的 tar 存档是不同的。首先,您将一大堆文件打包到存档中,然后将压缩应用于整个文件堆。因此,要在内部搜索,必须首先解压缩整个存档,即像这样的东西(再次伪代码(:
make and change to temporary directory
tar -xZf ${archive}
grep -R ${seachstring} ./
然而,tar 存档本身只是一堆"粘合"在一起的文件,中间有一些关于它们的文件名和大小的信息。因此,您可以简单地将存档解压缩到管道中,忽略文件矛状并搜索它
zcat file | grep
zgrep
在Solaris 服务器上不起作用。如果要求在给定文件已压缩的目录中的 a/all 文件中查找模式,则可以使用以下命令。
gzgrep 'pattern' filename
或
gzgrep 'bangladesh' BD2017*
<</div>
div class="one_answers">使用 zgrep:
zgrep 'bangladesh' BD2017*