1、整行替换
例如,我的文本:
[root@node3 ~]# cat test.txt [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/ enabled=1 hahaha gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
我要把"enabled=1 hahaha"变成 “111111111”
sed -i 4c111111111 test.txt # 4是vim里边看到的行数,c是行,1111111是替换后内容 # 适用于整行替换 [root@node3 ~]# sed -i 4c111111111 test.txt [root@node3 ~]# cat test.txt [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/ 111111111 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591



