Skip to main content
4 of 5
The proposed regex would leave out color codes with three digits such as `^[[334m`.
Konrad Rudolph
  • 549.4k
  • 142
  • 967
  • 1.3k

According to Wikipedia, the [m|K] in the sed command you're using is specifically designed to handle m (the color command) and K (the "erase part of line" command). Your script is trying to set absolute cursor position to 60 (^[[60G) to get all the OKs in a line, which your sed line doesn't cover.

(Properly, [m|K] should probably be (m|K) or [mK], because you're not trying to match a pipe character. But that's not important right now.)

If you switch that final match in your command to [mGK] or (m|G|K), you should be able to catch that extra control sequence.

./somescript | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" 
Jeff Bowman
  • 96.2k
  • 19
  • 227
  • 266