直接编辑文件选项-i
替换操作:s命令,全面替换标记g
-e选项允许在同一行里执行多条命令
sed -i -e 's/OPEN/1/g' -e 's/UP/1/g' -e 's/L4OK/4/g' -e 's/L7OK/7/g' $stat_file
sed -i -e 's/DOWN/0/g' -e 's/L4TOUT/40/g' -e 's/L7TOUT/70/g' $stat_file
sed -i 's?# Timeout=3?Timeout=30?g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's?# Include.**.conf?Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf?' /usr/local/zabbix/etc/zabbix_agentd.conf
#!/bin/bash
#modify file:/usr/local/zabbix/etc/zabbix_agentd.conf
sb="# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf"
sa="Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf"
file='/usr/local/zabbix/etc/zabbix_agentd.conf'
sed -i 's?# Timeout=3?Timeout=30?g' $file
sed -i 's?# Include.**.conf?'"${sa}"'?g' ${file}
# sed -i 's?# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf?Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf?' $file