Mac shell 替换文件夹下所有文件中的某一字符串 sed: 1: “xxx“: extra characters at the end of d command

shell 替换文件夹下所有文件中的某一字符串

#!/bin/sh
#cd 后面的内容为执行文件夹,即需要替换字符串的文件夹
cd ~/directory

#遍历文件,并对文件中的内容进行全部替换
for file in ./*
do
	sed -i '' 's/stringbefore/stringafter/g' $file
done

普通的编写sed -i 命令为

sed -i 's/stringbefore/stringafter/g' $file

运行的过程中遇到报错信息如下:
sed: 1: “xxx”: extra characters at the end of d command

Mac中sed -i 命令需要为

sed -i '' 's/stringbefore/stringafter/g' $file

Guess you like

Origin blog.csdn.net/MDJ_D2T/article/details/117924382
Recommended