I’m trying to use sed to process some output of a command that is generating colored lines (it’s git diff, but I don’t think that’s important). I’m trying to match a ‘+’ sign at the beginning of the line but this is being confounded by the color code, which precedes the ‘+’. Is there a simple way to deal this this issue, or do I need to use some complicated regular expression to match the color code.
If possible I’d like to preserve the coloring of the line.
If you must have the coloring then you’re going to have to do something ugly:
That
^[is actually a raw escape character (Ctrl+V ESC in bash, ASCII 27). You can usecat -vto figure out the necessary escape sequences:This sort of thing will work fine with the GNU versions of
sed,awk, … YMMV with non-GNU versions.An easier way would be to turn of the coloring:
But you can trade pretty output for slightly ugly regular expressions.