sed 在mac 上的坑

作者: Thinkando | 来源:发表于2019-03-01 12:30 被阅读15次

    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
    

    相关文章

      网友评论

        本文标题:sed 在mac 上的坑

        本文链接:https://www.haomeiwen.com/subject/qwqduqtx.html