How can I run a replacement in sed only when part of a line I don't want to replace includes one of a list of substrings?
For example, say, the substrings used to mark lines I want to replace are 123
, 456
and abc
in the following sample input:
# jdggsdihdf, 123
# ljhkhkjh, 789
# fagdfhgghjasfa, 456
# jsajspjsdighishxc, abc
# jgasdjGA, def
Thus, only those lines should be modified, and the lines with 789
or def
should be left alone:
Replaced text, 123
# ljhkhkjh, 789
Replaced text, 456
Replaced text, abc
# jgasdjGA, def
I know how to do simple s/foo/bar/
replacements, so I could do s/^# .*,/Replaced text,/
, but I don't know how to do that only when the line also matches a string in one of the fields I don't want to change with the replacement.