in reply to Replacing text - problem with $1 variable

Try either:

perl -pi -e 's/brad(.+?)bill/brian$1bob/gm;' *.txt

or

perl -pi -e "s/brad(.+?)bill/brian\$1bob/gm;" *.txt

Seems like $1 is interpolated before your code is run.

Mats

Replies are listed 'Best First'.
Re: Re: Replacing text - problem with $1 variable
by kr00z3r (Initiate) on Sep 03, 2003 at 10:20 UTC
    Woohoo! It works when changing " to '. Thanks! :)

    What I'm trying to do is replacing some code in some php-files from $_GET["whatever"] to get("whatever) and $_POST["whatever"] to post("whatever") so I can make some functions that handles all http-arguments with special characters like æøåöü by converting them to html-tags like ø

    Martin
      perl -pi -e 's/\$_(GET|POST)\[([^\]]*)]/lc($1) . "($2)"/egm;' test.php
      Assuming there's no nested square brackets inside your argument list to $_GET[] and $_POST[], that will work.