http://qs1969.pair.com?node_id=811520


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']});