我在solaris中有一个.tar.gz格式的文件。我想从中获取一些内容。我正在使用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
答案 0 :(得分:2)
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
答案 1 :(得分:1)
使用zgrep:
zgrep 'bangladesh' BD2017*
答案 2 :(得分:1)
zgrep
在solaris服务器上不起作用。如果要求压缩后在目录内的一个/所有文件中查找模式,则可以使用以下命令。
gzgrep 'pattern' filename
或
gzgrep 'bangladesh' BD2017*