Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: perl one liner to replace matching string

by vinoth.ree (Monsignor)
on Jun 10, 2018 at 08:05 UTC ( #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 (Bishop) 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
Node Status?
node history
Node Type: note [id://1216296]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-09-19 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?