Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: perl one line helper

by ph0enix (Friar)
on Dec 07, 2009 at 15:34 UTC ( #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? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2023-06-03 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (7 votes). Check out past polls.

    Notices?