Link to home
Start Free TrialLog in
Avatar of cels9
cels9

asked on

Replace script

How i do a script that replaces determinate word of determinate file for other word? for example:
file.txt : expert-exchange.com cool!
/perl script.pl expert-exchange.com great!
file.txt : expert-exchange.com great!

tbkz.
Avatar of ozo
ozo
Flag of United States of America image

#!/usr/bin/perl
$replace=pop;
$find=pop;
{local $^I=".bak"; local @ARGV=qw(file.txt);
 while( <> ){
    s/$find \S+/$find $replace/g;
     print;
 }
}
Unless you meant to call
/perl script.pl file.txt cool! great!
in which case you might use
 #!/usr/bin/perl
$replace=pop;
$find=pop;
{local $^I=".bak";
 while( <> ){
    s/\b$find\b/$replace/g;
     print;
 }
}
Avatar of cels9
cels9

ASKER

the 1st or the 2nd? tnx
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cels9

ASKER

ozo ure the one :P u request all questions... good!