Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: perl one line helper

by ph0enix (Friar)
on Dec 07, 2009 at 15:34 UTC ( [id://811520]=note: print w/replies, xml ) Need Help??


in reply to perl one line helper

perl -ne 's/TEMP_SGW_PDP_ADDR=.*$/TEMP_SGW_PDP_ADDR=47.104.153.163/; print $_' < test.sh

Replies are listed 'Best First'.
Re^2: perl one line helper
by johngg (Canon) on Dec 07, 2009 at 16:32 UTC

    Using the -p switch and a positive look-behind will save some typing. I also prefer the safety net of in-place editing with the -i switch.

    $ cat test.sh some stuff export SERVING_GW_ADDR=47.104.153.103 export TEMP_SGW_PDP_ADDR=47.104.153.103 more stuff $ perl -pi.BAK -e ' > s/(?<=TEMP_SGW_PDP_ADDR=).*$/47.104.153.163/;' test.sh $ head -99 test.sh* ==> test.sh <== some stuff export SERVING_GW_ADDR=47.104.153.103 export TEMP_SGW_PDP_ADDR=47.104.153.163 more stuff ==> test.sh.BAK <== some stuff export SERVING_GW_ADDR=47.104.153.103 export TEMP_SGW_PDP_ADDR=47.104.153.103 more stuff $

    I hope this of interest.

    Cheers,

    JohnGG

Re^2: perl one line helper
by happy.barney (Friar) on Dec 07, 2009 at 19:35 UTC
    did you heard about switch -p :-) ?
    Little bit improved version:
    perl -pe 's/(?<=TEMP_SGW_PDP_ADDR=).*$/47.104.153.163/'
      For more information about -p see perlrun.

      print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-06-19 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.