Reputation: 1433
I'm trying to add a header to a stdout
stream. The best I could come up with is the following, using a temp file and cat
's hyphen option. How can I turn this into a one-liner pipeline? Thanks.
python myscript.py myparm > tmp
echo 'a,b,c' | cat - tmp > output
Upvotes: 5
Views: 2751
Reputation: 361849
No temp file or unnecessary cat
needed:
{ echo 'a,b,c'; python myscript.py myparm; } > output
Note that both the spaces around the curly braces and the trailing ;
are required.
Upvotes: 12
Reputation: 2959
None of the solutions above worked for my case. But, something similar to the accepted solution worked:
(echo "a,b,c" && my-command)
for example:
(echo "a,b,c" && seq 3) | tee new.log
cat new.log
a,b,c
1
2
3
Upvotes: -1
Reputation: 7812
This is the method I use to pipe data through gzip in cgi scripts. Everything in the while loop goes through the output unless you specifically redirect it inside the loop (This can be pretty useful).
RUNONCE=""
while ([ ! "$RUNONCE" ]) do
RUNONCE=true
echo stuff
exec stuff
cat stuff
#whatever you want
done >output
Upvotes: -1
Reputation: 158070
You can use process substitution:
echo 'a,b,c' | cat - <(python myscript.py myparm) > output
or:
cat <(echo 'a,b,c') <(python myscript.py myparm) > output
Upvotes: 6