In sed, how can I do pattern replacement when a line doesn't contain certain pattern?
I know how to do it in vi or vim.
For example, to replace 'rabbit' to 'hare' when the line does not contain 'animal', I can do
:g!/animal/s/rabbit/hare/g
I want to do the same thing for hundreds of files under a directory using foreach, find and sed. When the line does not contain '= (Dtype)', I want to replace 'Dtype val1 = expression;' to 'Dtype val1 = (Dtype)(expression);'. But excluding cases like 'Dtype *pval = expression;'. That is, I want to put (Dtype) casting for non-pointer assignments. I tried
>foreach i (`find . -name \*.c`)
? sed -e 'g!/ = (Dtype)/s/Dtype \([a-z].*\) = \(.*\);/Dtype \1 = (Dtype)(\2);/g' $i >! tmp
? mv tmp $i
? end
But this 'g!/pattern/s/patter1/pattern2/g' doesn't work in sed. What's the correct command?