Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: perl one liner to replace matching string

by vinoth.ree (Monsignor)
on Jun 10, 2018 at 08:05 UTC ( [id://1216296]=note: print w/replies, xml ) Need Help??


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:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216296]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-26 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found