Skip to main content
Logo

sed-remove-ansi-colors-from-output

April 29, 2023
1 min read

#sed-remove-ansi-colors-from-output.md

Using ansi colors can be very helpful to see script out[put. Example of cleaning ansi color codes from output before putting it in your log. You may want to keep them since cat would still handle it. However if you don’t like your logs with unreadable codes this is an example of cleaning it first with sed.

Terminal window
# crontab -l
00 22 * * * /root/scripts/backup.sh -w 1 -t 192.168.1.112 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" > "/logs/`/bin/date +\%Y-\%m-\%d`-backup-192.168.1.112.log"