We want to remove ^[
, and all of the escape sequences.
sed is not working and is giving us this error:
$ sed 's/^[//g' oldfile > newfile; mv newfile oldfile; sed: -e expression #1, char 7: unterminated `s' command $ sed -i '' -e 's/^[//g' somefile sed: -e expression #1, char 7: unterminated `s' command
Escaping is a method of quoting single characters. The escape (\) preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.
You can use regexes to remove the ANSI escape sequences from a string in Python. Simply substitute the escape sequences with an empty string using re. sub(). The regex you can use for removing ANSI escape sequences is: '(\x9B|\x1B\[)[0-?]
Are you looking for ansifilter?
Two things you can do: enter the literal escape (in bash:)
Using keyboard entry:
sed 's/Ctrl-vEsc//g'
alternatively
sed 's/Ctrl-vCtrl-[//g'
Or you can use character escapes:
sed 's/\x1b//g'
or for all control characters:
sed 's/[\x01-\x1F\x7F]//g' # NOTE: zaps TAB character too!
commandlinefu gives the correct answer which strips ANSI colours as well as movement commands:
sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With