bash - Edit conf file without get in the file -
this question exact duplicate of:
i wonder know if there way edit conf file without getting in file , changing lines?
in case, need edit zabbix-agent conf file (located in /etc/zabbix/zabbix_agentd.conf) , there parameters in file need change, such server name, debuglevel, , others.
normally edit file using vim , change lines, idea edit file directly bash, don`t know if possible.
for example, if need change parameter debuglevel, @ bash run:
# /etc/zabbix/zabbix_agentd.conf.debuglevel=3
this doesn`t works, problem...
does knows??
i tested david said, didn`t solved problem... there lines in file commented , need uncomment them, , there lines need change.
for example, line above:
# debuglevel=3
i need change to:
debuglevel=3
and line:
server=127.0.0.1
i need change ip of zabbix server name, this:
server=172.217.28.142
is there other way?
if understand question correctly, want sed -i (the -i option allows sed edit file in place, , -i.bak same create backup of original file .bak extension)
to change debuglevel=3 debuglevel=4 in file /etc/zabbix/zabbix_agentd.conf, can do:
# sed -i.bak "/debuglevel/s/[0-9][0-9]*$/4/" /etc/zabbix/zabbix_agentd.conf if misinterpreted question, please let me know.
to change values @ end
example input file
$ cat file.txt debuglevel=3 example use
$ sed -i "/debuglevel/s/[0-9][0-9]*$/4/" file.txt $ cat file.txt debuglevel=4 to remove comments
you can virtually same thing uncomment parameters of interest, example:
# sed -i.bak "/debuglevel/s/^#//" /etc/zabbix/zabbix_agentd.conf in each case, sed searching label in first set of forward slashes /.../, next substitute command called s , expression between next set of forward slashes, e.g. /^#/ (^ match @ beginning), if matched, replaced follows in next set // (nothing in remove comment case).
you need adjust values required match each parameter need find , replace. let me know if have further problems , problem is.
Comments
Post a Comment