Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 something

Similar to how cat - works:

echo "START OF OUTPUT" | cat - file.txt
share|improve this question
grep isn't truncating pipe output; echo simply doesn't read its standard input. – cjm Feb 13 '13 at 6:16
up vote 6 down vote accepted

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.

share|improve this answer

Use a subshell to group output like this,

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

share|improve this answer

This will accomplish what you want

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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