sed 在mac 上的坑
2019-03-01 本文已影响15人
Thinkando
1. 备份
- linux
# 将找到的 hello 替换为 world,并且直接保存修改到文件
sed -i 's/hello/world/g' hello.txt
- mac
# mac 需要在在 -i 之后加上一对引号,来指定备份格式,如果不需要备份,引号里的内容可以为空。
sed -i '' 's/hello/world/g' hello.txt
2. 换行
- linux
#在第一行插入hello
sed -i '1i\ hello ' hello.txt
- mac
sed -i '' '1i\
hello' hello.txt