sed -i command for in-place editing to work with both GNU sed and BSD/OSX

后端 未结 7 1137
攒了一身酷
攒了一身酷 2020-11-28 04:09

I\'ve got a makefile (developed for gmake on Linux) that I\'m attempting to port to MacOS, but it seems like sed doesn\'t want to cooperate. What I

7条回答
  •  不知归路
    2020-11-28 04:19

    Actually, doing

    sed -i -e "s/blah/blah/" files
    

    doesn't do what you expect in MacOS either. Instead it creates backup files with -e extension.

    The proper command for MacOS is

    sed -i "" -e "s/blah/blah/" files
    

    On Linux, remove the space between -i and "" (see related answer)

    sed -i"" -e "s/blah/blah/" files
    

提交回复
热议问题