Insert linefeed in sed (Mac OS X)

前端 未结 9 1022
长情又很酷
长情又很酷 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:09

    Try this:

    $ echo test1234foo123bar1234 | sed "s/\(1234\)/\n\1/g"
    test
    1234foo123bar
    1234
    

    From Sed Gnu doc

    g
        Apply the replacement to all matches to the regexp, not just the first. 
    

提交回复
热议问题