I run another script.sh. He displays some of his logs. How to make it so that a prefix is ​​added to each line of the script, for example, [script]. That is the original log

строкастрока 

and changed

 [script] строка[script] строка 
  • Not quite clear. Does he write logs by himself? Or use syslog? - Anton Shevtsov
  • He writes a log by himself. It looks like this: ./script.sh >> log - stanislav
  • echo 'line' | awk '{print "[script]" $ 0}'> /tmp/out.txt? - Anton Shevtsov

1 answer 1

Can do so

 ./script.sh | while read line; do echo "[script] $line"; done >> log 

The prefix in the loop is added to each line.

  • It works! - stanislav