in reply to Re: Removing special chars from line
in thread Removing special chars from line

I removed the s parameter from tr but the unprintables are still there. is there a way to remove all non-printable chars and keep the whitespace at the same time?

Replies are listed 'Best First'.
Re^3: Removing special chars from line
by graff (Chancellor) on Oct 19, 2011 at 01:44 UTC
    It looks like the stream of characters that you want to remove are all cases of "backspace" (expressed as a four-character sequence 'esc [ 1 D', but with the 'esc' character transliterated by your terminal window display into two printable characters: "^" and "[" ), followed by one of:  / - \ |

    It's the ascii-art version of the rotating clock-hand. To get rid of that specific pattern, use a regex substitution -- I think it would go something like this (not tested):

    s{ (?: \e \[ 1 D [\\/|-] )+ }{}gx;
    The "\e" represents the escape character, the open-square-bracket needs to be preceded by backslash to be treated as a literal character, and the four "rotating hand" characters are in a character class that follows "D" (the hyphen needs to be either last or first in the class list, to avoid being interpreted as a range operator, and the backslash needs to be escaped, but "|" does not (and neither does "/", since I'm not using that as the regex delimiter).