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
Solved

replace value in file between two other values

Posted on 2004-10-07
2
169 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
2 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 75 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…

808 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