Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add prefix to every line when print to output with tee

Tags:

bash

shell

I have command like this

command | tee /dev/tty | grep ...

that say prints

hello
world

I would like to change this so every line from the command output to be prefixed, in the output or it to looks, say:

# hello
# world
like image 803
gsf Avatar asked Jul 18 '14 19:07

gsf


1 Answers

bash Process substitution might help

printf 'hello\nworld\n' | tee >(awk '{print "#"$0}' > /dev/tty) | grep hello
hello
#hello
#world
like image 116
iruvar Avatar answered Sep 25 '22 01:09

iruvar