I want to remove a fixed number of some backspace characters (\ b) from stdin. So far I have tried this:
echo -e "1234\b\b\b56" | sed 's/\b{3}//'
But that will not work. How can I achieve this using sed or some other Unix shell tool?
sed interprets \bas the word boundary. I got this to work in perl, for example:
\b
echo -e "1234\b\b\b56" | perl -pe '$b="\b";s/$b//g'
You can use the hex value for backspace:
echo -e "1234\b\b\b56" | sed 's/\x08\{3\}//'
You also need to remove the brackets.
tr:
tr
echo -e "1234\b\b\b56" | tr -d '\b' 123456
, Perl:
echo -e "1234\b\b\b56" | perl -pe 's/(\010){3}//'
sed:
echo "123\b\b\b5" | sed 's/[\b]\{3\}//g'
{ } {3}, \b .
{
}
{3}
[birryree@lilun ~]$ echo "123\b\b\b5" | sed 's/[\b]\{3\}//g' 1235
Note that you also want to remove characters to be deleted, see ansi2html.sh , which contains the processing, for example:
printf "12..\b\b34\n" | sed ':s; s#[^\x08]\x08##g; t s'
There is no need for Perl!
# version 1 echo -e "1234\b\b\b56" | sed $'s/\b\{3\}//' | od -c # version 2 bvar="$(printf '%b' '\b')" echo -e "1234\b\b\b56" | sed 's/'${bvar}'\{3\}//' | od -c
Source: https://habr.com/ru/post/1796053/More articles:Как создать facebook настенные сообщения и добавить сетчатую версию изображения - iphoneiPhone sdk - using a custom camera - iphoneBorovka Algorithm MST - javaJoin 3 tables using the Doctrine_RawSql object - joinLinq var and typed object - c #How do I start creating intellisense for my own javascript libraries in VS? - javascriptДиспетчер IIS 7.0 IIS не имеет опции "Управление пакетами" - installStatic class / method Stop application - c #What to do to get javascript intellisense for my own js library in Visual Studio - javascriptGoogle Chrome placement alignment issue - cssAll Articles