linux - using sed / awk to change variable values in config files -
this question has answer here:
i have few config files , wanting edit variable values using script. i've come across sed/awk this. have tried using following sed command on following config example, issue changes commented section actual one. did see can nth occurrence seams apply line, not entire file.
command:
sudo sed -i 's/server=.*/server=10.10.1.206/' /etc/zabbix/zabbix_agentd.conf file
### option: server # list of comma delimited ip addresses (or hostnames) of zabbix servers. # incoming connections accepted hosts listed here. # if ipv6 support enabled '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' treated equally. # # mandatory: no # default: # server=10.10.1.206 server=10.10.1.206
add regex anchor ^ replace on lines starting server
sudo sed -i 's/^server=.*/server=10.10.1.206/' /etc/zabbix/zabbix_agentd.conf the support anchors ^ , $ match start , end of pattern available in posix compatible sed versions.
an excerpt regular-expressions page,
anchors
[..] anchors not match characters. match position.
^matches @ start of string, ,$matches @ end of string.[..]
Comments
Post a Comment