• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

replace value in file between two other values

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
MatthewF
Asked:
MatthewF
1 Solution
 
rj2Commented:
$text=~s/host(?:name)?=[^;]+;/host=testhost;/g;
0
 
TintinCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now