如何使用给定文件中的适当值更新特定条目,
假设我有一个文件名 hello.conf,
/agent/process="starthelloJava",start="/opt/starthello.sh",start_dir="/opt/hello",start_args=""
/agent/process="stophelloJava",stop="/opt/stophello.sh",stop_dir=/opt/hello",stop_args="",stop_timeout="30"
更新starthelloJava
与
start_args="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/"
输出
/agent/process="starthelloJava",start="/opt/starthello.sh",start_dir="/opt/hello",start_args="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/"
清空start_args
进程starthelloJava
/agent/process="starthelloJava",start="/opt/starthello.sh",start_dir="/opt/hello",start_args=""
/agent/process="stophelloJava",stop="/opt/stophello.sh",stop_dir=/opt/hello",stop_args="",stop_timeout="30"
我正在做的方式很长,我正在根据输入重写整个文件。
这是我的方法,效率不高
cp hello.conf hello.conf_bak
remove entry first
cat /opt/CSCObac/agent/conf/agent.conf_bak | grep -v /opt/starthello.sh > hello.conf
echo "/agent/process=\"starthelloJava\",start=\"/opt/starthello.sh\",start_dir=\"/opt/hello\",start_args=\"-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/\" >> hello.conf