http://qs321.pair.com?node_id=1216296


in reply to Re: perl one liner to replace matching string
in thread perl one liner to replace matching string

I tried the below perl one liner to replace the "@Filetyp :" as "@Filetyp :c"

my $ext='c'; qx("perl -p -i -e \"s/(\@Filetyp\\s*?:)/\\1$ext/\" /path/test.c");

I am already doing it.Could you pls try like above perl one liner to replace the string?


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^3: perl one liner to replace matching string
by Athanasius (Archbishop) on Jun 10, 2018 at 08:28 UTC

    Ok, I get the same result as you reported. Playing around with it, I had to add two additional backslashes to get it to work as desired (not sure why):

    my $ext='c'; qx("perl -p -i.bak -e \"s/(\\\@Filetyp\\s*?:)/\\1$ext/\" ./path/test.c +"); # ^^

    (Note: I also had to specify an extension for the backup file.) This is on Windows; if your O/S is different, it may treat the backslashes differently.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      In response to: not sure why

      Similar findings: here and it was pretty heavily analyzed by AnomalousMonk in the following posts

      You are right I am writing this for windows, If it is linux/unix I could have used sed/awk.


      All is well. I learn by answering your questions...
        If it is linux/unix I could have used sed/awk.

        sed, gawk and many other GNU-ish *nix utilities are available in the UnxUtils port of these utilities to Windoze.


        Give a man a fish:  <%-{-{-{-<