开发者

regex to catch commented lines of a conf file

开发者 https://www.devze.com 2023-03-27 22:04 出处:网络
In order to find this line pm.max_children = 50 inside a conf file and change it to pm.max_children = 5, I am using this:

In order to find this line pm.max_children = 50 inside a conf file and change it to pm.max_children = 5, I am using this:

s/^\(pm.max_children = \).*/\15/

In the case, the line may or not be commented (with ';' or '#'). How can I deal with that in a single regex to work with sed?

If the CONF_FILE has this content:

pm.max_children = 500
;pm.max_children = 500
#pm.max_children = 500

This is what I need to accomplish:

pm.max_children = 5
pm.max_children = 5
pm.max_childr开发者_Python百科en = 5


sed on my machine doesn't seem to support ?, but you can use * instead:

s/^[#;]*[:space:]*\(pm.max_children = \).*/\15/

This matches 0 or more # or ; characters followed by 0 or more whitespace characters.

If you don't care what precedes your keyword, use this, which is simpler, but matches anything:

s/^.*\(pm.max_children = \).*/\15/
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号