【发布时间】:2014-02-05 02:19:15
【问题描述】:
我得到了这些文件:
bonds.txt.gz
bonds_201307.txt.gz
bonds_201308.txt.gz
bonds_201309.txt.gz
bonds_201310.txt.gz
bonds_201311.txt.gz
bonds_201312.txt.gz
我有一个 for 循环来遍历文件,解压缩它们,然后用 grep 找到一个字符串:
for f in `ls *.txt.gz`; do echo $f; zcat $f | grep MYBOND; done
如果我运行它,我会得到以下信息:
bonds.txt.gz
zcat: bonds.txt.gz.gz: No such file or directory
bonds_201307.txt.gz
zcat: bonds_201307.txt.gz.gz: No such file or directory
bonds_201308.txt.gz
zcat: bonds_201308.txt.gz.gz: No such file or directory
bonds_201309.txt.gz
zcat: bonds_201309.txt.gz.gz: No such file or directory
bonds_201310.txt.gz
zcat: bonds_201310.txt.gz.gz: No such file or directory
bonds_201311.txt.gz
zcat: bonds_201311.txt.gz.gz: No such file or directory
bonds_201312.txt.gz
zcat: bonds_201312.txt.gz.gz: No such file or directory
似乎 zcat 正在用额外的 .gz 扩展文件名 但是,当我尝试从命令行对文件进行 zcat 时,它并没有这样做,只是获取提供的文件名并完成其工作。为什么在循环调用时会发生?
我知道我可以通过使用 zgrep 或 find 来达到同样的目的,但我仍然有兴趣了解 zcat 的这种行为。 谢谢!
【问题讨论】:
-
您使用的是哪个版本的
zcat?zcat --version -
版本为:
zcat 1.3.5