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

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
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.