如何使用sed替换退格符(\ b)?

Thi*_*uda 3 linux bash shell sed

我想从stdin中删除固定数量的一些退格字符ocurrences(\ b).到目前为止,我试过这个:

echo -e "1234\b\b\b56" | sed 's/\b{3}//'
Run Code Online (Sandbox Code Playgroud)

但它不起作用.如何使用sed或其他一些unix shell工具实现这一目的?

Jon*_*ley 9

您可以使用十六进制值作为退格键:

echo -e "1234\b\b\b56" | sed 's/\x08\{3\}//'
Run Code Online (Sandbox Code Playgroud)

你还需要逃避牙箍.


Eug*_*ash 5

您可以使用tr

echo -e "1234\b\b\b56" | tr -d '\b'
123456
Run Code Online (Sandbox Code Playgroud)

如果要删除连续三个退格键,可以使用Perl:

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