Append or modify keys in conf files using sed/bash one-liner

前端 未结 2 841
轮回少年
轮回少年 2021-01-21 22:03

I often have to modify files such as sysctl.conf, and I\'m familiar with using sed to replace existing values.

Is there a way to append the new key/value pa

2条回答
  •  野的像风
    2021-01-21 22:34

    Use below pseudo code:

    if (grep -q key); then
        sed...
    else
        echo key=value >> $CONFIG_FILE
    fi
    

提交回复
热议问题