Solved

replace value in file between two other values

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl exit code 2 245
Perl script to parse xml file 2 96
Perl output collect 7 64
Perl DBI Transactions Using Custom Module 7 41
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now