[英]Save command output at filename
I've got this problem, where I want to save an output of a command as a filename and stream output from a different command (within the same script) to that file. 我遇到了这个问题,我想将命令的输出保存为文件名,然后将来自不同命令(在同一脚本中)的输出流式传输到该文件。 I wasn't able to find a solution online, so here goes.
我无法在线找到解决方案,所以去了。 Below is the code I have:
下面是我的代码:
zgrep --no-filename 'some-patter\|other-pattern' /var/something/something/$1/* | awk -F '\t' '{printf $8; printf "scriptLINEbreakerPARSE"; print $27}' | while read -r line ; do
awk -F 'scriptLINEbreakerPARSE' '{print $1}' -> save output of this as a filename
awk -F 'scriptLINEbreakerPARSE' '{print $2}' >> the_filename_from_above
done
So basically I want to use the first awk in the loop to save the output as a filename and then the second awk output will save to the file with that filename. 因此,基本上我想在循环中使用第一个awk将输出另存为文件名,然后将第二个awk输出保存到具有该文件名的文件中。
Any help would be appreciated guys. 任何帮助将不胜感激的家伙。
You're doing too much work. 您做的工作太多了。 Just output to the desired file in the first awk command:
只需在第一个awk命令中输出到所需文件:
zgrep --no-filename 'some-patter\|other-pattern' /var/something/something/$1/* |
awk -F '\t' '{printf $27 > $8}'
See https://www.gnu.org/software/gawk/manual/html_node/Redirection.html 参见https://www.gnu.org/software/gawk/manual/html_node/Redirection.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.