本文介绍了如何将多个命令的输出重定向到一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个bash脚本,它具有以下两个命令:
i have a bash script, that has the following two commands:
ssh host tail -f /some/file | awk ..... > /some/file &
ssh host tail -f /some/file | grep .... > /some/file &
我怎样才能使这两个命令的输出被引导到同一个文件中。
How can i make the output of both commands be directed into the same file.
推荐答案
请注意,你可以减少SSH调用的次数:
Note you can reduce the number of ssh calls:
{ ssh host tail -f /some/file |
tee >(awk ...) >(grep ...) >/dev/null
} > /some/file &
例如:
{ echo foobar | tee >(sed 's/foo/FOO/') >(sed 's/bar/BAR/') > /dev/null; } > outputfile
cat outputfile
fooBAR
FOObar
这篇关于如何将多个命令的输出重定向到一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!