using sed to replace two patterns within a larger pattern
Posted
by
Hair of the Dog
on Super User
See other posts from Super User
or by Hair of the Dog
Published on 2011-01-23T19:54:23Z
Indexed on
2012/11/27
23:13 UTC
Read the original article
Hit count: 160
sed
|replacement
Using sed how could I replace two patterns within a larger pattern on a single line?
Given a single line of text I want to find a pattern (Let's call this the outer pattern) and then within that outer pattern replace two inner patterns.
Here's a one line example of the input text:
Z:\source\private\main\developer\foo\setenv.sh(25): export 'FONTCONFIG_PATH'="$WINE_SHARED_SUPPORT/X11/etc/fonts"
In the example above the outer pattern is "/^.*([[:digit:]]+):/" which should equal "Z:\source\private\main\developer\foo\setenv.sh(25):" The two inner patterns are "/^[A-Za-z]:/" and "/\/".
Another way to phrase my question is: Using sed I know how to perform replacements of a pattern using the "s" command, but how do I limit the range of "s" command so it only works on the portion of the input string up to the "(25):"?
The ultimate result I am trying to get is the line of text is transformed into this:
/enlistments/source/private/main/developer/foo/setenv.sh(25): export 'FONTCONFIG_PATH'="$WINE_SHARED_SUPPORT/X11/etc/fonts"
© Super User or respective owner