?
Solved

replace value in file between two other values

Posted on 2004-10-07
2
Medium Priority
?
173 Views
Last Modified: 2010-05-18
I have a huge file and who like to replace all instances of

host=something;

The value of host could also be

hostname="something";

I gather I need to find each occurrence of the word host and replace whether value is there from the equal sign to the semi-colon. I will replace the value of host to be “testhost”
0
Comment
Question by:MatthewF
[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
2 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 300 total points
ID: 12251639
$text=~s/host(?:name)?=[^;]+;/host=testhost;/g;
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12253416
And to rj2's regex from the command line, do:

 perl -i.bak -pe 's/host(?:name)?=[^;]+;/host=testhost;/g' hugefile

the -i.bak will create a backup of the file before doing the subsitution.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

770 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