[linux-l] regex

Christoph Biedl cbiedl at gmx.de
Sa Feb 4 16:41:34 CET 2012


Olaf Radicke wrote...

> Okay, trotzdem bekomme ich nicht das was ich erwarte:
> 
> or at gkiste:~$ echo 'bla \\section{a} \section{b} foo \\section{c} bar
> \section{d}' | sed 's/ \\section/ /g'
(hier sollte wohl ein Zeilenumbruch rein)
> bla \\section{a} {b} foo \\section{c} bar {d}
> 
> Nach meinem Verständnis müsste hier das herauskommen:
> 
>  \{a} {b} foo \{c} bar {d}

Laß mich Dich weiter verwirren:

    $ cat /tmp/re-test
    echo 'bla \\section{a} \section{b} foo \\section{c} bar \section{d}' | sed 's/ \\section/ /g'

    $ bash /tmp/re-test
    bla \\section{a} {b} foo \\section{c} bar {d}

    $ dash /tmp/re-test
    bla {a} {b} foo {c} bar {d}

In Verbindung mit backslashes ist echo einfach nur böse. Daß das
echo-builtin bei der dash Escape-Sequenzen interpretiert, ist zwar
dokumentiert, aber trotzdem überraschend.

Vermutlich ist /bin/echo die bessere Wahl, oder auch gleich printf.

    Christoph



Mehr Informationen über die Mailingliste linux-l