Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid writing progress bars to file in linux

Tags:

linux

bash

stdout

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?

like image 472
mgoldwasser Avatar asked Sep 07 '25 22:09

mgoldwasser


1 Answers

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
like image 102
karakfa Avatar answered Sep 10 '25 02:09

karakfa