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

后端 未结 13 2079
心在旅途
心在旅途 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:39

    The following works for me on Linux and OS X:

    sed -i' '

    e.g. for a file f containing aaabbaaba

    sed -i' ' 's/b/c/g' f

    yields aaaccaaca on both Linux and Mac. Note there is a quoted string containing a space, with no space between the -i and the string. Single or double quotes both work.

    On Linux I am using bash version 4.3.11 under Ubuntu 14.04.4 and on the Mac version 3.2.57 under OS X 10.11.4 El Capitan (Darwin 15.4.0).

提交回复
热议问题