Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a series of files with entries(namespaces in source code) like

FW.WGS.Web.HHH.Controls, FW.WGS.Web.HHH.Email,  FW.WGS.Web.HHH.Account, etc    and some with entries 
FW.WGS.Web.Controls,     FW.WGS.Web.Email,      FW.WGS.Web.Account, etc

Using sed (or some other linux/unix tool) I want to change all FW.WGS.Web.Controls/Email/Account/etc for FW.WGS.Web.HHH.Control/Email/Account/etc.

My current sed command matches 's/WGS.Web/WGS.Web.\HHH/g' is not suitable - I end up with entries like

FW.WGS.Web.HHH.HHH.Email

So I need to prevent sed from matching lines that already have "HHH" in them.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

In sed, you can use /pattern/!s/pattern/, e.g.

/HHH/!s/WGS\.Web/WGS\.Web\.HHH/g
share|improve this answer
add comment
perl -pe 's/WGS\.Web(?!\.HHH)/$&.HHH/g'

(where $& is a shortcut for the matched text)

See perlre.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.