Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: sed isn't working within a perl script

by Corion (Pope)
on Oct 19, 2012 at 09:05 UTC ( #999885=note: print w/replies, xml ) Need Help??

in reply to sed isn't working within a perl script

You will need to modify your string and properly quote the backslash so that it gets passed correctly to the shell. I recommend the following approach:

use strict; use warnings; my $cmd = "sed -ie 's/\(.*\)/Number => \1/' test.txt"; print "Launching [$cmd]\n"; system($cmd) == 0 or die "Couldn't launch [$cmd]: $! / $?";

You will see that your single backslashes did not get passed through to the sed command. You will need to double them.

Replies are listed 'Best First'.
Re^2: sed isn't working within a perl script
by nvivek (Vicar) on Oct 19, 2012 at 10:39 UTC
    You're right. Thank you so much. I just doubled the backslashes used in grouping and referring grouped pattern. Then it worked properly. I got confused because I didn't get any error while executing that code.
Re^2: sed isn't working within a perl script
by McA (Priest) on Oct 19, 2012 at 09:19 UTC


    is it possible that a backslash gets lost in your solution or simply when posting your solution? I can't see a difference.

    Best regards

      I did only add the debugging help, not a solution to the problem itself.

        Hi corion,

        I'm sorry. I have to admit that it seems that I stopped reading before the last sentence. That's more worse as I also prefer helping to help youself.

        Excuse me.

        Best regards

      corion posted the original with error checking, so the OP can see/understand what went wrong (how to debug, error check)

      and instructions on how to fix the problem (something for the OP to type)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999885]
[Discipulus]: yes but in a little house with fireplace; 2 friends and lot of beverages..
[Corion]: Discipulus: Aah, so it's not really walking through quick-changing weather
[Discipulus]: no fear: moonday i'll back (unless a big quake ... ;=)
[Corion]: Discipulus: Being out in nature is great, at least as long as you have a dry place to sleep and a warm fire ;)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-02-24 09:16 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (353 votes). Check out past polls.