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

前端 未结 12 2181
情歌与酒
情歌与酒 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 06:02

    Here's how to apply environment variables to template file (no backup need).

    1. Create template with {{FOO}} for later replace.

    echo "Hello {{FOO}}" > foo.conf.tmpl
    

    2. Replace {{FOO}} with FOO variable and output to new foo.conf file

    FOO="world" && sed -e "s/{{FOO}}/$FOO/g" foo.conf.tmpl > foo.conf
    

    Working both macOS 10.12.4 and Ubuntu 14.04.5

提交回复
热议问题