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/
精彩评论