大杂烩,味道好

sed 在mac 上的坑

2019-03-01  本文已影响15人  Thinkando

1. 备份

# 将找到的 hello 替换为 world,并且直接保存修改到文件
 sed -i  's/hello/world/g' hello.txt
# mac 需要在在 -i 之后加上一对引号,来指定备份格式,如果不需要备份,引号里的内容可以为空。
sed -i '' 's/hello/world/g' hello.txt

2. 换行

#在第一行插入hello
sed -i '1i\ hello ' hello.txt
sed -i '' '1i\
hello' hello.txt
上一篇 下一篇

猜你喜欢

热点阅读