Replace comma with newline in sed on MacOS?

后端 未结 13 2024
借酒劲吻你
借酒劲吻你 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:26

    Though I am late to this post, just updating my findings. This answer is only for Mac OS X.

    $ sed 's/new/
    > /g' m1.json > m2.json
    sed: 1: "s/new/
    /g": unescaped newline inside substitute pattern
    

    In the above command I tried with Shift+Enter to add new line which didn't work. So this time I tried with "escaping" the "unescaped newline" as told by the error.

    $ sed 's/new/\
    > /g' m1.json > m2.json 
    

    Worked! (in Mac OS X 10.9.3)

提交回复
热议问题