我得到了这些文件:
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 的这种行为感兴趣。谢谢!