Replace comma with newline in sed on MacOS?

后端 未结 13 2015
借酒劲吻你
借酒劲吻你 2020-11-27 09:27

I have a file of id\'s that are comma separated. I\'m trying to replace the commas with a new line. I\'ve tried:

sed \'s/,/\\n/g\' file

b

13条回答
  •  一整个雨季
    2020-11-27 10:15

    Use an ANSI-C quoted string $'string'

    You need a backslash-escaped literal newline to get to sed. In bash at least, $'' strings will replace \n with a real newline, but then you have to double the backslash that sed will see to escape the newline, e.g.

    echo "a,b" | sed -e $'s/,/\\\n/g'
    

    Note this will not work on all shells, but will work on the most common ones.

提交回复
热议问题