How do you strip ANSI colour codes or carriage returns from tool output?
BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' ci.log > clean.log
tr -d '\r' < output.txt
kubectl logs pod --no-color 2>/dev/null || kubectl logs pod | sed -E 's/\x1B\[[0-9;]*m//g'
Prefer turning colours off at the source (--no-color, NO_COLOR=1, TERM=dumb) so log parsers and alert rules see plain text.
More on Text processing: grep, sed, awk, cut, sort, uniq
What are the most useful `grep` flags?BeginnerWhat is the difference between basic, extended and Perl regular expressions in grep?IntermediateWhat are the core `sed` commands you use in automation?BeginnerWhy does `sed -i` behave differently on macOS and Linux?IntermediateHow do you use variables inside a `sed` expression safely?AdvancedWhat is the structure of an `awk` program?Beginner