Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sed line to place a a string based on two matches

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just:

sed '/SOME_MATCH2/{ /SOME_MATCH1/s/STRING_TO_REPLACE/MY_REPLACE_STRING/ }'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading