Text Processing – Search and Replace Using SED

replacesearchsedtext processing

I need to find all occurrences of AAsomeArbitraryStringBB and replace it with CCsomeArbitraryStringDD.

So

AAHelloBB
Text
AAByeByeBB

becomes

CCHelloDD
Text
CCByeByeDD.

It's important to note that the replacement string contains part of the search string.

Best Answer

This is basic task for sed command:

sed 's/AA\(someArbitraryString\)BB/CC\1DD/g'

Eventually if you want to do this for all "arbitrary strings":

sed 's/AA\(.*\)BB/CC\1DD/g'
Related Question