Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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
perl -pe 's/WGS\.Web(?!\.HHH)/$&.HHH/g'

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

See perlre.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .