Home > Software engineering >  sed line to place a a string based on two matches
sed line to place a a string based on two matches

Time:02-21

say i have a sed line that replaces text on a line with a substring match, like so...

sed '/SOME_MATCH1/s/STRING_TO_REPLACE/MY_REPLACE_STRING/'

which works fine, but what if i wanted to match on more than just 'SOME_MATCH1'? What if i wanted sed to match two strings before it tries the replace? Like if i only wanted it to try a replace when both SOME_MATCH1 and SOME_MATCH2 is present in the string?

I've tried everything and cant get it to do what i need it to. Any help would be greatly appreciated.

CodePudding user response:

Just:

sed '/SOME_MATCH2/{ /SOME_MATCH1/s/STRING_TO_REPLACE/MY_REPLACE_STRING/ }'
  • Related