Montag, 27. September 2010

sed (Posix-RE) vs. perl (PCRE)

What I wanted to setup today is a simple command to comment out certain lines in a textfile. I realized that using sed in this particular case was not possible because I have to use look around functionality; so, something like this won't work:

sed -i 's/.*(?=http-proxy-(exceptions|host|port))/# /' /path/to/file


Perl to the rescue, where PCRE with full look around is possible, the above command turns to the following one-liner:

perl -i -pe 's/.*(?=http-proxy-(exceptions|host|port))/# /'
/path/to/file

... which works like a charm.

0 Kommentare:

Kommentar veröffentlichen