I have a string with 3 capture groups and would like to preserve the first and third but perform a substitution on the second. How do I express this in sed?
Concretely, I have an input string like:
top-level.subpath.one.subpath.two.subpath.forty-five
And I want to preserve the part before the first ., shorten the middle part to the first letter of every word, and preserve the part after the last .. The result should look like:
top-level.s.o.s.t.s.forty-five
For preserving the capture groups, I have:
sed -r 's/([^.]*)(.*)(\..*)/\1...\3/'
which gets me:
top-level....forty-five
For converting something like .subpath.one.subpath.two.subpath to only initials, I have:
sed -r 's/(\.[^.])[^\.]*/\1/g'
which gets me:
.s.o.s.t.s
I'd like to essentially apply that second sed expression to capture group 2. Is there some way I can chain sed substitutions to perform that second substitution on only the second capture group while retaining the first and third?