tan*_*ngi 20 regex string bash replace sed
我正在尝试使用sed但使用正则表达式取消注释文件内容(例如:[0-9] {1,5})
# one two 12
# three four 34
# five six 56
Run Code Online (Sandbox Code Playgroud)
以下是有效的:
sed -e 's/# one two 12/one two 12/g' /file
Run Code Online (Sandbox Code Playgroud)
但是,我想要的是使用正则表达式模式替换所有匹配而不输入数字但保留结果中的数字.
F. *_*uri 16
为了符合样本问题,简单地说
sed 's/^# //' file
Run Code Online (Sandbox Code Playgroud)
就足够了,但是如果只需要在包含特定正则表达式的某些行上删除注释,那么你可以使用conditionnal 地址:
sed '/regex/s/^# //' file
Run Code Online (Sandbox Code Playgroud)
因此,包含的所有行都regex将被取消(如果行以a 开头#)
...... regex可能是[0-9]$这样的:
sed '/[0-9]$/s/^# //' file
Run Code Online (Sandbox Code Playgroud)
将#在包含数字作为最后一个字符的行的开头删除.
| 归档时间: |
|
| 查看次数: |
69114 次 |
| 最近记录: |