Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
regex捕获conf文件的注释行_Regex_Bash_Sed - Fatal编程技术网

regex捕获conf文件的注释行

regex捕获conf文件的注释行,regex,bash,sed,Regex,Bash,Sed,为了在conf文件中找到这一行pm.max_children=50,并将其更改为pm.max_children=5,我使用以下命令: s/^\(pm.max\u children=\)./\15/ 在这种情况下,行可以被注释,也可以不被注释(使用“;”或“#”)。我如何在一个正则表达式中处理这些问题,以便与sed合作 如果CONF_文件包含以下内容: pm.max_children = 500 ;pm.max_children = 500 #pm.max_children = 500 这就是我

为了在conf文件中找到这一行
pm.max_children=50
,并将其更改为
pm.max_children=5
,我使用以下命令:

s/^\(pm.max\u children=\)./\15/

在这种情况下,行可以被注释,也可以不被注释(使用“;”或“#”)。我如何在一个正则表达式中处理这些问题,以便与sed合作

如果CONF_文件包含以下内容:

pm.max_children = 500
;pm.max_children = 500
#pm.max_children = 500
这就是我需要完成的:

pm.max_children = 5
pm.max_children = 5
pm.max_children = 5

我的机器上的sed似乎不支持
,但您可以使用
*

s/^[#;]*[:space:]*\(pm.max_children = \).*/\15/
这与0个或多个
#
匹配字符后跟0个或更多空白字符

如果您不关心关键字前面的内容,请使用此选项,它更简单,但可以匹配任何内容:

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

谢谢,诺亚。在关键字之前出现的唯一内容是“#”或者什么都没有。没有空间了。所以我可以这样做:
s/^[#]*\(pm.max\u children=\)./\15/g
并完成交易。