Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
2  
grep isn't truncating pipe output; echo simply doesn't read its standard input. –  cjm Feb 13 '13 at 6:16

3 Answers 3

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

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

Use a subshell to group output like this,

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

share|improve this answer

Your Answer

 
discard

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.