Sign up ×
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.

For example, I got from some command some lines

$ some-command

Now I'd like to add chaining command, that modifies output.

$ some-command | other-command
Hi John Bye
Hi Bob Bye
Hi Lucy Bye

How to write other-command? (I'm a novice in bash)

share|improve this question

3 Answers 3

up vote 10 down vote accepted


$ some-command | awk '{print "Hi "$1" Bye"}'


$ some-command | sed 's/\(.*\)/Hi \1 Bye/'


Using awk:

$ echo -e "John\nBob\nLucy" | awk '{print "Hi "$1" Bye"}'
Hi John Bye
Hi Bob Bye
Hi Lucy Bye

Using sed:

$ echo -e "John\nBob\nLucy" | sed 's/\(.*\)/Hi \1 Bye/'
Hi John Bye
Hi Bob Bye
Hi Lucy Bye
share|improve this answer
You forgot some-command | paste -d\ <(printf '%s\n' Hi Hi Hi) - <(printf '%s\n' why Why WHY??) – kojiro Feb 5 '14 at 3:17
@kojiro - wasn't feeling the paste way today, thanks 8-) – slm Feb 5 '14 at 3:20

The code below reads line after line, storing it in variable LINE. Inside the loop, each line is written back to the standard output, with the addition of "Hi" and "Bye"


while read LINE ; do
   echo "Hi $LINE Bye"  
share|improve this answer

Bash while loop and pipes :

echo -e "John\nBob\nLucy" | while read n; do echo "hi $n bye"; done
share|improve this answer

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.