Skip to content
Advertisement

Using sed with regex to match varying lines

I’m having some issues used sed to match a regex pattern. An example would be with the following lines:

spring-core-4.0.0 should be spring-core-4.1.0

spring-web-4.0.0 should be spring-web-4.1.0

I want the regex to match any characters in between spring and the version number. I’m not sure if I need to do something else for sed to remember what those characters are in each line.

sed -E 's/spring-([a-z]+)-4.0.0/spring-([a-z]+)-4.1.0/' file.txt

The current output is placing the regex pattern in the output, instead of matching it. Thanks for any tips.

Advertisement

Answer

$ sed 's/(spring-[^-]*-)4.0.0/14.1.0/' file
spring-core-4.1.0
spring-web-4.1.0
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement