Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

convert sed to zsh



I'm trying to convert a 'sed' filter to native zsh.  Here's the sed:

    bar=$( echo $foo |
    sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" )

Here's my candidate zsh:

    bar=$foo//$'\x1B'\[([0-9](#c0,2)(;[0-9](#c0,2))#)#[mGK]/}

... so far it's working, but I'm nervous about it. In another context it seems I have to backslash the semi-colon, but here it seems ok either way, but of course it should be one or the other. The 'sed' is of course the kosher way (I believe) of removing color codes and various other escapes like "\e[K" that seem to hang around colorized output of 'grep' and so on. With several different forms of color codes, I want to be sure I get this right. Unless of course zsh already has a stock way of stripping escape sequences, which it very well might.



Messages sorted by: Reverse Date, Date, Thread, Author