{"id":1896,"date":"2023-04-30T07:57:49","date_gmt":"2023-04-30T12:57:49","guid":{"rendered":"https:\/\/blog.ls-al.com\/?p=1896"},"modified":"2023-04-30T07:57:49","modified_gmt":"2023-04-30T12:57:49","slug":"sed-remove-ansi-colors-from-output","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/sed-remove-ansi-colors-from-output\/","title":{"rendered":"sed remove ansi colors from output"},"content":{"rendered":"

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.<\/p>\n

# crontab -l\n00 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<\/code>-backup-192.168.1.112.log\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Using ansi colors can be very helpful to see script out[put. Example of cleaning ansi color codes from output before<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1896","post","type-post","status-publish","format-standard","hentry","category-bash"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1896"}],"version-history":[{"count":1,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1896\/revisions"}],"predecessor-version":[{"id":1897,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1896\/revisions\/1897"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}