[英]zcat pipe to grep
ls -ltr|grep 'Mar 4'| awk '{print $9 }'|zcat -fq |grep 12345
I want to find all files modified on a certain date and then zcat them and search the fiels for a number string.我想找到在某个日期修改的所有文件,然后对它们进行 zcat 并在文件中搜索数字字符串。
the above doesn't work because it searches the file name for the string not the file itself.以上不起作用,因为它在文件名中搜索字符串而不是文件本身。
Any help?有什么帮助吗?
M米
Use xargs
to run the grep on the filenames output by awk:使用
xargs
在 awk 的文件名 output 上运行 grep:
ls -ltr | grep 'Mar 4' | awk '{print 9}' | xargs zcat -fq | grep 12345
Or, I guess, run the rest of the pipe from awk itself.或者,我猜,从 awk 本身运行 pipe 的 rest。
Try using find
instead.尝试使用
find
代替。 And/or xargs
.和/或
xargs
。
If I read your command line correctly, its zcat that is trying to unpack the filenames instead of their content.如果我正确阅读了您的命令行,则它的 zcat 正在尝试解压缩文件名而不是其内容。 Use xargs to solve this:
使用 xargs 来解决这个问题:
ls -ltr|grep 'Mar 4'| awk '{print $9 }'|xargs zcat -fq |grep 12345
In addition to the fine answers about using xargs
or find
, you can also get rid of an extra process by eliminating zcat
and piping to zgrep
or grep -Z
instead.除了关于使用
xargs
或find
的详细答案之外,您还可以通过消除zcat
和管道到zgrep
或grep -Z
来摆脱额外的过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.