Is it possible with sed to replace a line with capture groups from the regex?
I have this regex, please note that this is fixed, I cannot change it.
simple sample(.*)
This is what I want:
This is just a simple sample line with some text
Change to:
line with some text
I need something like this:
sed '/simple sample \(.*\)/c \1'
Which now outputs:
1
Anybody knows if you can use capture groups in sed with the change line function?
Like this?
echo "This is just a simple sample line with some text" | \
sed 's/simple sample \(.*\)/\n\1/;s/.*\n//'
The idea is simple: replace the whole regexp match with the captured group preceded by a newline. Then replace everything up to and including the first newline with nothing. Of course, you could use a marker other than the newline.
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