in reply to Removing special chars from line

tr/\040-\176//csd;

You can't use all three options with tr/// at the same time.    It looks like you only need:

tr/\040-\176//cd;

Replies are listed 'Best First'.
Re^2: Removing special chars from line
by ataX (Initiate) on Oct 18, 2011 at 14:41 UTC
    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?
      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).