sed command with -i option failing on Mac, but works on Linux

前端 未结 12 2107
情歌与酒
情歌与酒 2020-11-22 05:04

I\'ve successfully used the following sed command to search/replace text in Linux:

sed -i \'s/old_link/new_link/g\' *

However,

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 05:52

    As the other answers indicate, there is not a way to use sed portably across OS X and Linux without making backup files. So, I instead used this Ruby one-liner to do so:

    ruby -pi -e "sub(/ $/, '')" ./config/locales/*.yml
    

    In my case, I needed to call it from a rake task (i.e., inside a Ruby script), so I used this additional level of quoting:

    sh %q{ruby -pi -e "sub(/ $/, '')" ./config/locales/*.yml}
    

提交回复
热议问题