In a file that has any garbled text before and after a section that is marked by patterns START and END (specific strings that occur only once each and in the correct order and on the same line). I would like to do some string manipulation ONLY on the part between START and END
Example input:
aomodi3hriq32| ¶³r 0q93aoiSTART_this_is_to_be_modified_ENDaqsdofuha23uru| ²23i ii3uhfia
oawpo3<9"§ A hSTART_this_also_needs_modification_ENDqa 032/a237(°1Q"§ >A_this_
START changeme ENDnot_this_modias
In terms of sed-operations, the substring (and the substring only) between START and END should be modified as if I used sed 's/_this_// ; s/modi/MODI/ ; y/as/45/'.
Example output:
aomodi3hriq32| ¶³r 0q93aoiSTARTi5_to_be_MODIfied_ENDaqsdofuha23uru| ²23i ii3uhfia
oawpo3<9"§ A hSTART4l5o_need5_MODIfic4tion_ENDqa 032/a237(°1Q"§ >A_this_
START ch4ngeme ENDnot_this_modias
awk with FS="START|END" fails as the OFS cannot be set to multiple values at different positions.
I tried using sed with a nested command substitution and different separators (~) but failed and also fear that there might be characters before START/after END that will mess with the command (e.g. a /). The idea was to only select the "inner" substring and do the operations then use it as part of the replacement:
sed "s/^\(.*\)START.*END\(.*\)$/\1$(sed 's~^.*START~~
s~END.*~~
s~_this_~~
s~modi~MODI~
y~as~45~' infile)\2/" infile
I am not familiar with e.g. perl .... but whatever it takes.
Is there any way to make a set of sed-operations apply to a REGEX-matched substring of a line only?
NUL,CR... say most control characters except for newline and tab. But anything may appear.