有一个文件sample.txt。此文件的内容为
..some content...
### [http]
# [http]因此,我必须在#之前删除[http],以便最终修改的文件看起来像
..some content...
### [http]
[http]我想用sed命令来完成它。那么具体的命令是什么呢?
发布于 2017-05-02 12:38:46
尝尝这个
sed -i 's/^# //' file1因此,它将在每一行的开头搜索#和一个空格,并将其替换为null。
如果您只想用# [http]替换[http],那么请使用
sed -i 's/^# \[http]/[http]/' file1发布于 2017-05-02 12:37:41
sed方法,仅在#子字符串之前删除[http]:
sed -i 's/^# *\(\[http]\)/\1/' file产出:
..some content...
### [http]
[http]\1 -指向第一个捕获的组(...)
https://unix.stackexchange.com/questions/362604
复制相似问题