in reply to Retrieve & Replace strings in one Perl line.

perl -ne 's/napre/Text1/gi; print if /\bnapre/i || /\bjupiter/i;' GPPRegistry

Replies are listed 'Best First'.
Re^2: Retrieve & Replace strings in one Perl line.
by johngg (Canon) on Nov 12, 2007 at 23:00 UTC
    I'm not sure from the way the question is worded but, since it is a registry file the requirement might be just to change those lines with "jupiter" and "napre" (are they hostnames?) leaving other lines in the file untouched. -pe might be more appropriate.

    perl -pi.bak -e "s/\bnapre/Text1/gi; s/\bjupiter/Text2/gi;" GPPRegistr +y

    Just a guess.

    Cheers,

    JohnGG

Re^2: Retrieve & Replace strings in one Perl line.
by Noame (Beadle) on Nov 13, 2007 at 08:06 UTC
    The output of the command is:
    perl -ne "print if /\\bnapre/i || /\\bjupiter/i;" GPPRegistry.temp.reg
    "DBLogin"="napre"
    "DSN"="jupiter"
    "DBLogin"="napre"
    "Login"="napre"
    "Password"="napre"
    "DBLogin"="napre"
     
    I want in the same command to replace "napre" with "TEST1" and present it (Not change the file yet).
    after this command the fields include "napre" are despaired and the replacement of "napre" weren't be shown
     
    perl -ne 's/napre/Text1/gi; print if /\bnapre/i || /\bjupiter/i;' GPPRegistry.temp.reg
    "DSN"="jupiter"
    "DSN"="jupiter"