How do I replace backspace characters (\b) using sed? How do I replace backspace characters (\b) using sed? shell shell

How do I replace backspace characters (\b) using sed?


You can use the hexadecimal value for backspace:

echo -e "1234\b\b\b56" | sed 's/\x08\{3\}//'

You also need to escape the braces.


sed interprets \b as a word boundary. I got this to work in perl like so:

echo -e "1234\b\b\b56" | perl -pe '$b="\b";s/$b//g'


You can use tr:

echo -e "1234\b\b\b56" | tr -d '\b'123456

If you want to delete three consecutive backspaces, you can use Perl:

echo -e "1234\b\b\b56" | perl -pe 's/(\010){3}//'