Text Editing – How to Exclude Some Matches with sed

sedtext editing

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.

Best Answer

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

/HHH/!s/WGS\.Web/WGS\.Web\.HHH/g
Related Question