Sed 查找某一行,并替换这行内容

Sed 中 /c 是替换的意思,可以用这个 /c 来实现查找并替换一整行的需求。

比如查找 iburst 所在的行,并把这行内容替换成自己希望的内容。

[root@ceph01 ~]# more /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst

[root@ceph01 ~]# sed -i '/iburst/cserver 192.168.46.7 iburst' /etc/chrony.conf
[root@ceph01 ~]# more /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.46.7 iburst

注意,上面的命令中有 /c

posted @ 2023-01-08 22:01  人间词话  阅读(613)  评论(0)    收藏  举报