bash zgrep 目录中的多个 gz 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21549038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
zgrep multiple gz files in directory
提问by Mithrand1r
I have problem executing zgrep
command for looking for word
in the directory where I have almost 1000 *.gz
files.
我在执行zgrep
命令以word
在我有近 1000 个*.gz
文件的目录中查找时遇到问题。
I am trying with:
我正在尝试:
find /var/www/page/logs/ -name "*.gz" -exec zgrep '/index.php' {} \;
result is:
结果是:
GET : '/index.php'
GET : '/index.php'
GET : '/index.php'
And it works.I get list of occurance of index.php
with no file name where it was found. It is kind of useless for me unless i knew in which files (filename) it appears.
它有效。我得到index.php
了没有文件名的出现列表。除非我知道它出现在哪个文件(文件名)中,否则它对我来说没什么用。
How can i fix it?
我该如何解决?
回答by devnull
You could supply the -H
option to list the filename:
您可以提供-H
列出文件名的选项:
find /var/www/page/logs/ -name "*.gz" -exec zgrep -H '/index.php' {} \;
If you wanted only the list of matching files, use -l
:
如果您只想要匹配文件的列表,请使用-l
:
find /var/www/page/logs/ -name "*.gz" -exec zgrep -l '/index.php' {} \;
回答by Mark Setchell
Make grep search in two files, then it will tell you which one it found it in:
在两个文件中进行 grep 搜索,然后它会告诉你它在哪个文件中找到的:
find /var/www/page/logs/ -name "*.gz" -exec zgrep '/index.php' {} /dev/null \;
And it won't take long to search in /dev/null.
在 /dev/null 中搜索不会花费很长时间。
Here is an example without /dev/null:
这是一个没有 /dev/null 的例子:
zgrep chr your.gz
>chrMCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken
>chrgi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
and with /dev/null
和 /dev/null
zgrep chr your.gz /dev/null
your.gz:>chrMCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken
your.gz:>chrgi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]