mgoldwasser
mgoldwasser

Reputation: 15394

Avoid writing progress bars to file in linux

I have a process that prints output, but this output also includes loading bars.

I would like to both write this output to a file and display this output.

Normally I could just do:

./my_process.sh | tee -a my_log_file.txt

or

./my_process.sh >> my_log_file.txt
tail -f my_log_file.txt

This prints everything to my terminal, however it also prints EVERYTHING to the log file, including each step of the progress bar!

I would like to exclude progress bar iterations from getting printed to the log file.

For my purposes, any line with a carriage return can be excluded from the log file. How can I exclude carriage return lines from getting appended to the log file while still printing them to stdout on the terminal?

Upvotes: 4

Views: 1719

Answers (1)

karakfa
karakfa

Reputation: 67467

You can filter the tee before logging

for example

$ echo -e "progress_ignore\r\nlog this\nprogress_ignore\r" | tee >(awk '!/\r/' >> output.log)
progress_ignore
log this
progress_ignore

$ cat output.log
log this

Upvotes: 5

Related Questions