Solved

replace value in file between two other values

Posted on 2004-10-07
2
168 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
syslog unix file 20 72
Move Function in Perl Script 2 68
Parse csv file and generate graphs in HTML in bash 8 181
quoting a comma separated list 20 84
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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