Insert linefeed in sed (Mac OS X)

前端 未结 9 1020
长情又很酷
长情又很酷 2020-11-29 01:36

How do I insert a newline in the replacement part of sed?

This code isn\'t working:

sed \"s/\\(1234\\)/\\n\\1/g\" input.txt > output.txt
         


        
9条回答
  •  心在旅途
    2020-11-29 02:14

    Get a GNU sed.

    $ brew install gnu-sed
    

    Then your command will work as expected:

    $ gsed "s/\(1234\)/\n\1/g" input.txt
    test
    1234foo123bar
    1234
    

    nb: you may get GNU sed thanks to mac ports too.

提交回复
热议问题