2

Is there any way to have an echo at the end of a pipe simply append to the current output rather than removing it all? For example, how can I keep the output for my cat and grep and add "END OF OUTPUT" to the end of the output from the same pipe:

$ cat file.txt | grep 'foo' | echo "END OF OUTPUT"
something foo 
foo
foo something
END OF OUTPUT

Similar to how cat - works:

echo "START OF OUTPUT" | cat - file.txt
  • 2
    grep isn't truncating pipe output; echo simply doesn't read its standard input. – cjm Feb 13 '13 at 6:16
6

Like this:

{ grep foo file.txt; echo END OF OUTPUT; } > output.txt

That groups commands without starting a subshell (except with the Bourne shell).

You could do:

grep foo file.txt | cat - <(echo END OF OUTPUT) > output.txt

(with ksh, bash or zsh) but that creates a few more extra processes and pipes for no extra benefit.

3

Use a subshell to group output like this,

(grep foo file.txt; echo "END OF OUTPUT") > output.txt

1

This will accomplish what you want

$ cat file.txt | grep 'foo' ; echo "END OF OUTPUT"
  • sorry late reply, didnt see others reply. – Vishnu Kumar Feb 13 '13 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.