My problem seems to be simple but I found it suprisingly difficult to convert into sed expression.
I need to ‘underscorize’ names between certain tokens in a file. So if the line has tokens : and = I need to convert ‘multi word name’ into ‘multi_word_name’ between these two tokens.
I know it is fairly easy to do two step match anything between the tokens and then global replace spaces with underscores but I can’t find a way of retaining unmatched part of line for writing back into file.
This might work for you (GNU sed, tr and bash):
or just using sed: