bashsedtr

convert tab to unit separator using sed or tr with bash


as title - I want to convert tabs in an input file / stdin to asciii unit separators on stdout / redirected file.

All of the following have no effect

tr 0x09 0x1f
tr '0x09' '0x1f'
sed  's#0x09#0x1f#g'
sed s#0x09#0x1f#g

have no effect


Solution

  • Neither tr nor sed understand 0x09 and 0x1f. In bash, you can use the $'...' quotes with C-style backslash escape sequences. This style understands both \t and \x... notations.

    printf 'a\tb\n' | sed $'s/\t/\x1f/g'
    printf 'a\tb\n' | tr '\t' $'\x1f'