gsf
gsf

Reputation: 7232

add prefix to every line when print to output with tee

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

Upvotes: 6

Views: 2664

Answers (1)

iruvar
iruvar

Reputation: 23364

bash Process substitution might help

printf 'hello\nworld\n' | tee >(awk '{print "#"$0}' > /dev/tty) | grep hello
hello
#hello
#world

Upvotes: 6

Related Questions