简体   繁体   English

zcat 到 grep 文件名

[英]zcat to grep with file name

ls -ltr|grep 'Mar  4'| awk '{print $9 }'|xargs zcat -fq |grep  12345

I'm now using this command to list the records that contain my numeric string how can i alos get this command to print the name of the file the strings were found in?我现在使用这个命令来列出包含我的数字字符串的记录我怎样才能得到这个命令来打印找到字符串的文件的名称?

thanks谢谢

Use zgrep使用zgrep

BTW.顺便提一句。 what you're trying to do can be done with find你想做的事情可以用find来完成

find  -newermt 'Mar 4' -and ! -newermt 'Mar 5' -exec zgrep -l '12345' {} \;

If you use zgrep instead of zcat+grep (which does the same), you do it like this option like this:如果你使用zgrep而不是 zcat+grep (它做同样的事情),你这样做像这样的选项:

ls -ltr | grep 'Mar 4' | awk '{print $9}' | xargs zgrep 12345

Pass the -t option to xargs , causing it to print the command it is running (the zcat command, including the filename) before running it.-t选项传递给xargs ,使其在运行之前打印正在运行的命令( zcat命令,包括文件名)。 The command is printed to stderr, so it will not interfere with your pipe.该命令会打印到 stderr,因此它不会干扰您的 pipe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM