I have a line of text which looks like this:
/src/my_module_my_branch/my_module
Example: /src/goodcode_dev/goodcode
and I need to convert it to:
/src/my_branch/my_module
Example: /src/dev/goodcode
The problem both module and branch can include underscores.
So I need first to identify the module from the third part and use it to extract out the branch name.
Is there a way using sed to do such conversions?
If you have GNU sed, this should work. It assumes everything begins with
/src/.In English:
Invoke
sedwith extended regex (-r) so that+will work. Match beginning of line,/src/, group 1: one or more non-slashes,_, group 2: one or more non-slashes,/, group 1, end of line. Change to/src/, group 2,/, group 1.