views:

304

answers:

2

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)

+6  A: 

Try

( echo 1; echo 2 ) > file.txt

That spawn a subshell and executes the commands there

{ echo 1; echo 2; } > file.txt

is possible, too. That does not spawn a subshell (the semicolon after the last command is important)

Johannes Weiß
What shell are you using? I tried the first in windows' cmd.exe and the contents of the file are '1; echo 2' ; the 2nd option doesn't work at all.
Cristi Diaconescu
Cristi Diaconescu
Johannes Weiß
A: 

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.

Epcylon
Did you read the side note near the end?
Cristi Diaconescu