I am new to sed and I am trying to figure out if it is possible to add a prefix to all words between two markers that are encountered after a string match in a line
suppose I have a line
abc xyz PAT1 { PAT2 PAT3 PAT4 } cdf fgd
PAT1 is the string match and the markers being { and } in this case
I want the result to be
abc xyz PAT1 { prefix_PAT2 _prefix_PAT3 prefix_PAT4 } cdf fgd
I can write a C code to do this, but I am new to scripting, so I was wondering if it is possible in sed ?
I know how to add prefix to certain columns of a line if a string is encountered
but PAT2 PAT3 PAT4 can be any column and there may be more than 3 of them
Input file contain:
abc xyz PAT1 { PAT2 PAT3 PAT4 } cdf fg
Try below code:
sed -i -e 's/PAT*/prefix_PAT/2g' filename
it will update your input file (filename) output:
abc xyz PAT1 { prefix_PAT2 prefix_PAT3 prefix_PAT4 } cdf fgd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With