replace value in file between two other values

I have a huge file and who like to replace all instances of


The value of host could also be


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”
Who is Participating?
rj2Connect With a Mentor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.