How do I replace : characters with newline?

后端 未结 4 1126
野的像风
野的像风 2020-12-22 08:05

I looked at a very similar question but was unable to resolve the issue Replace comma with newline in sed

I am trying to convert : characters in a strin

4条回答
  •  独厮守ぢ
    2020-12-22 08:22

    You do not need echo -e because you have \n in sed, not in echo statement. So, the following should work (note that I have changed '\n' to \n):

    echo -e 'this:is:a:test' | sed "s/\:/\n/g"
    

    or

    echo  'this:is:a:test' | sed "s/\:/\n/g"
    

    Also note that you do not need to escape : so the following will work too (thanks to @anishsane)

    echo  'this:is:a:test' | sed "s/:/\n/g"
    

    Below is just to reiterate why you need -e for echo

    $ echo -e "hello \n"
    hello
    
    $ echo  "hello \n"
    hello \n
    

提交回复
热议问题