shell脚本mac平台执行sed命令报错

时间:2021-02-11 15:34:35

mac执行sed命令报错

$ touch testing.txt
$ echo "this is mkyong.com" > testing.txt
$ cat testing.txt
this is mkyong.com
$ sed -i 's/mkyong/google/g' testing.txt
sed: 1: "testing.txt": undefined label 'esting.txt'


文档中有说明,mac在执行sed -i 时候要添加一个参数 
This  sed -i 's/mkyong/google/g' testing.txt  command is working properly in Linux, but hits “undefined label” error message on Mac OS X.

这里添加需要的参数

sed -i '.bak' 's/mkyong/google/g' testing.txt
ls -ls
8 -rw-r--r--  1 mkyong  staff  19 Aug  2 14:22 testing.txt
8 -rw-r--r--  1 mkyong  staff  19 Aug  2 14:21 testing.txt.bak
cat testing.txt
this is google.com
cat testing.txt.bak

this is mkyong.com