Bash: Update a variable within a file

前端 未结 3 1809
滥情空心
滥情空心 2021-01-26 03:41

I know this is a simple answer and I could probably keep digging around on Google before I stroll across the answer. But I am on a tight schedule and I was hoping for an easy re

3条回答
  •  别那么骄傲
    2021-01-26 04:00

    sed -i -e '/^ONBOOT=/s|.*|ONBOOT=yes|; /^BOOTPROTO=/s|.*|BOOTPROTO=static|' file
    

    Also try:

    sed -i -re 's|^(ONBOOT=).*|\1yes|; s|^(BOOTPROTO=).*|\1static|' file
    

    Or

    sed -i -e 's|^\(ONBOOT=\).*|\1yes|; s|^\(BOOTPROTO=\).*|\1static|' file
    

提交回复
热议问题