How do I replace : characters with newline?

后端 未结 4 1135
野的像风
野的像风 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条回答
  •  猫巷女王i
    2020-12-22 08:28

    I'll presume that you have the string in a variable already. This uses the parameter expansion substitution operator to replace every : with a newline, which is specified using a $'...'-quoted string. Both features are bash extensions to the standard, and may not work in another shell.

    $ foo="this:is:a:test"
    $ bar="${foo//:/$'\n'}"
    $ echo "$bar"
    this
    is
    a
    test
    

提交回复
热议问题