`tee` 命令相当于*输入*?
unix tee
命令将标准输入拆分为 stdout 和文件。
我需要的是相反的工作方式,将多个输入合并到一个输出 - 我需要连接两个(或更多)命令的标准输出。
不确定这个应用程序的语义应该是什么 - 让我们假设每个参数都是一个完整的命令。
示例:
> eet "echo 1" "echo 2" > file.txt
的内容的文件,
1
2
应该生成一个包含我尝试过
> echo 1 && echo 2 > zz.txt
但它不起作用。
旁注:我知道我可以将每个命令的输出附加到文件中,但我想一次性完成此操作(实际上,我想将合并的输出通过管道传输到另一个程序)。< br> 另外,我可以自己推出,但只要我能负担得起,我就会很懒:-)
哦,是的,如果它能在 Windows 中运行那就太好了(尽管我猜任何 bash/linux-)有风味的解决方案有效,通过 UnxUtils/msys/etc)
The unix tee
command splits the standard input to stdout AND a file.
What I need is something that works the other way around, merging several inputs to one output - I need to concatenate the stdout of two (or more) commands.
Not sure what the semantics of this app should be - let's suppose each argument is a complete command.
Example:
> eet "echo 1" "echo 2" > file.txt
should generate a file that has contents
1
2
I tried
> echo 1 && echo 2 > zz.txt
It doesn't work.
Side note: I know I could just append the outputs of each command to the file, but I want to do this in one go (actually, I want to pipe the merged outputs to another program).
Also, I could roll my own, but I'm lazy whenever I can afford it :-)
Oh yeah, and it would be nice if it worked in Windows (although I guess any bash/linux-flavored solution works, via UnxUtils/msys/etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
生成一个子 shell 并执行命令
,也是可能的。 这不会产生子 shell(最后一个命令后面的分号很重要)
Try
That spawn a subshell and executes the commands there
is possible, too. That does not spawn a subshell (the semicolon after the last command is important)
我想您想要的是并行运行两个命令,并将两个输出合并到另一个命令。
我会这样做:
其中“echo 1”和“echo 2”是生成输出的命令,“cat”是将接收合并输出的命令。
I guess what you want is to run both commands in parallel, and pipe both outputs merged to another command.
I would do:
Where "echo 1" and "echo 2" are the commands generating the outputs and "cat" is the command that will receive the merged output.
回声1> zz.txt && 回声2>> zz.txt
应该可以。 您真正要做的就是依次运行两个命令,其中第一个命令重定向到一个文件,然后,如果成功,您运行另一个命令,将其输出附加到您首先编写的文件的末尾。
echo 1 > zz.txt && echo 2 >> zz.txt
That should work. All you're really doing is running two commands after each other, where the first redirects to a file, and then, if that was successful, you run another command that appends its output to the end of the file you wrote in the first place.