sed in-place flag that works both on Mac (BSD) and Linux

后端 未结 13 2303
心在旅途
心在旅途 2020-11-22 08:18

Is there an invocation of sed todo in-place editing without backups that works both on Linux and Mac? While the BSD sed shipped with OS X seems to

13条回答
  •  庸人自扰
    2020-11-22 08:40

    There is no way to have it working.

    One way is to use a temporary file like:

    TMP_FILE=`mktemp /tmp/config.XXXXXXXXXX`
    sed -e "s/abc/def/" some/file > $TMP_FILE
    mv $TMP_FILE some/file
    

    This works on both

提交回复
热议问题