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.
file.txt : expert-exchange.com cool!
/perl script.pl expert-exchange.com great!
file.txt : expert-exchange.com great!
tbkz.
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;
}
}
/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;
}
}
ASKER
the 1st or the 2nd? tnx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ozo ure the one :P u request all questions... good!
ASKER
ozo pls request my other question: https://www.experts-exchange.com/questions/20949411/Downloading-all-image-files-of-determinate-page.html tnx.
$replace=pop;
$find=pop;
{local $^I=".bak"; local @ARGV=qw(file.txt);
while( <> ){
s/$find \S+/$find $replace/g;
print;
}
}