This is what I want to do:
If I encounter a pattern like
someVarX: val1
I want to insert
someVarY: val2
on the next line
…BUT HERE IS THE CATCH:
someVarX: val1 can have a number preceding blank spaces (indentation) counting anywhere between 0 and N and I also want to repeat that exact indentatation on the next line. So if someVarX: val1 has 3 preceding blank spaces, then I also want someVarY: val2 to have 3 preceding blank spaces.
This is what I tried:
s/\n( +)someVarX: val1/\n${1}someVarX: val1\n${1}someVarY: val2/
hoping that ${1} would insert the capture group from the search pattern into the replace string but got:
sed: command garbled: ...
The OS os SunOS 5.10. I couldn’t run sed --version, it told me the option –version was illegal.
Any idea?
This is what finally worked:
It had to be done on two lines of a sed S&R spec file, let’s call it
snrspec.sed, which also contained other S&R instructions:and then I called sed:
However, I would prefer to do it in a single line, if anyone knows how to, as it would obviously be more elegant. But the above worked and I performed my massive S&R operation.