使用 tee 打印到输出时为每一行添加前缀

gsf*_*gsf 5 bash shell

我有这样的命令

command | tee /dev/tty | grep ...
Run Code Online (Sandbox Code Playgroud)

那说打印

hello
world
Run Code Online (Sandbox Code Playgroud)

我想改变这一点,以便命令输出中的每一行都带有前缀,在输出中或看起来像:

# hello
# world
Run Code Online (Sandbox Code Playgroud)

iru*_*var 5

bash进程替换可能会有所帮助

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