简体   繁体   English

使用sed和regex匹配不同的行

[英]Using sed with regex to match varying lines

I'm having some issues used sed to match a regex pattern. 我在使用sed匹配正则表达式模式时遇到了一些问题。 An example would be with the following lines: 以下行是一个示例:

spring-core-4.0.0 should be spring-core-4.1.0 spring-core-4.0.0应该是spring-core-4.1.0

spring-web-4.0.0 should be spring-web-4.1.0 spring-web-4.0.0应该是spring-web-4.1.0

I want the regex to match any characters in between spring and the version number. 我希望正则表达式在spring和版本号之间匹配任何字符。 I'm not sure if I need to do something else for sed to remember what those characters are in each line. 我不确定是否需要做其他事情让sed记住每一行中的那些字符。

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. 感谢您的提示。

$ sed 's/\(spring-[^-]*-\)4.0.0/\14.1.0/' file
spring-core-4.1.0
spring-web-4.1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM