Last active
November 30, 2023 07:56
-
-
Save geblanco/e3d305295b3e014a04886ef5d97ab81f to your computer and use it in GitHub Desktop.
Simple bash script to remove tqdm output from logfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Intended usage: | |
# - You run a super long script with fancy tqdm progress bars in a remote server as usual: | |
# | |
# nohup python super_long_script.py > super_long.log & | |
# # monitor as long as you want | |
# tail -f super_long.log | |
# ... some time later | |
# - Inspecting the log with a regular cat super_long.log works perfectly fine, the problem comes when you `less` it to | |
# inspect more carefully... less renders tqdm nasty, using this script fixes that | |
# | |
# cat super_long.log | striptqdm | less | |
# or simply | |
# striptqdm super_long.log | less | |
# relaxed version, may fail for certain strings: | |
# sed -r '/^ *[0123456789]+%.*$/d' | |
if [[ ! -t 0 && ! -p /dev/stdin ]]; then | |
cat | tr '\r' '\n' | sed -r '/^.*[0123456789]+%.*$/d' | sed -e '/^ *$/d' | |
else | |
cat $@ | tr '\r' '\n' | sed -r '/^.*[0123456789]+%.*$/d' | sed -e '/^ *$/d' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment