Reputation: 4702
I have a shell command that produces line based output. Let me call it magic
for the sake of the argument. For whatever output it produces, how can I just append another value to it? I would like to do it in a pipe. I tried for a long time to google this without any luck. It seems like I must be missing some obvious way to do it. Ideally, there would be another unix command called append
which given as standard input the output of any other command the same output along with its arguments.
What I am imagining:
magic
This returns:
apple
cherry
banana
magic | append taro
This returns:
apple
cherry
banana
taro
Does this append
command already exist with a different name? If so, what is it called?
Upvotes: 1
Views: 743
Reputation: 785156
Converting my comment to answer so that solution is easy to find for future visitors.
You may use grouping of command using { ...; }
to group multiple commands:
{ magic; echo 'taro'; }
And if you want to redirect output to a file then use:
{ magic; echo 'taro'; } > outfile
Upvotes: 1
Reputation: 4969
The best way is not to use a pipe, but anubhava's { magic; echo 'taro'; }
.
However, since you asked a pipe, you've opened up Pandora's box of possibilities.
magic|sed '$ataro'
is the first.
magic| awk '{print} END{print "taro"}'
as second.
Or a bash function:
hop(){
while read line; do
echo $line
done
echo $1
}
magic | hop taro
And so on.
Upvotes: 1