如何将多个命令的输出重定向到一个文件

问题描述:

我有一个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