udaya udaya - 1 month ago 7
Linux Question

Regex match for color response in linux

I have a colored response from one of my server. I have a regular expression which is NOT working on that server. If I go to any other server, the response comes in black and it matches fine. Also I took the response and tried out other regular expression matching web sites and t worked smooth.

Any suggestion how to match the specific regular expression OR how we can change the color setting for the text . The specific server is "CentOS release 5.5 (Final)"

Regards,
Udaya

Answer

Colors are contained in the output in the form of ANSI escape sequences. You can remove the color codes by replacing all occurrences of

\033\[[0-9;]+m

Or, since your output seems to be from ls, simply use its --color=never option.