So the idea is to replace matched pattern nas_... with nas_$SCL using $SCL variable in a file, but excluding 2 exact matches nas_mba && nas_tvr, which should not be replacedSo far I've got code excluding both matches, but also interfering with other unwanted matchessed -i s/nas_[^mt][^bv][^ar]/nas_$SCL/gI filename.xmlHow can I exclude only those 2 exact matches?Update:So far I've found next solutionsed -i /(nas_mba|nas_tvr)/! s/nas_.../nas_$SCL/but it skips a whole line if it has a match
sed: excluding serveral part strings from matched pattern
sed;replace
Here is how I would do it:sed -E '/(nas_mba|nas_tvr)/! s/nas_.../nas_bar/'Example:echo nas_mbanas_tvrnas_foo | sed -E '/(nas_mba|nas_tvr)/! s/nas_.../nas_bar/'nas_mbanas_tvrnas_barOnly nas_foo in the original text is replaced, while both nas_mba and nas_tvr are left untouched.Another example with more lines:echo nas_hat> nas_mba> nas_foo> nas_hat> nat_tvr> nas_cat> nas_dog | sed -E '/(nas_mba|nas_tvr)/! s/nas_.../nas_bar/'nas_barnas_mbanas_barnas_barnat_tvrnas_barnas_barIf you want to change in place, just add the -i option (if you use GNU sed you don't need -i  simply -i would suffice):sed -E -i  '/(nas_mba|nas_tvr)/! s/nas_.../nas_bar/' nas.txt cat nas.txt nas_barnas_mbanas_barnas_barnat_tvrnas_barnas_barTested under Mac OS X 10.11.6 and BSD sed.