Solved

Replace script

Posted on 2004-04-09
6
1,101 Views
Last Modified: 2006-11-17
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.
0
Comment
Question by:cels9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 10795352
#!/usr/bin/perl
$replace=pop;
$find=pop;
{local $^I=".bak"; local @ARGV=qw(file.txt);
 while( <> ){
    s/$find \S+/$find $replace/g;
     print;
 }
}
0
 
LVL 84

Expert Comment

by:ozo
ID: 10795359
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;
 }
}
0
 

Author Comment

by:cels9
ID: 10795766
the 1st or the 2nd? tnx
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 10796281
When the first is called as
perl script.pl expert-exchange.com great!
It replaces the word after "expert-exchange.com" with "great!" in file.txt

when the second is called as
perl script.pl file,txt cool! great!
it replaces the word "cool!" with "great!" in "file.txt"
 
Is either of those close to what you wanted?
0
 

Author Comment

by:cels9
ID: 10797550
ozo ure the one :P u request all questions... good!
0
 

Author Comment

by:cels9
ID: 10797568
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question