Replace comma with newline in sed on MacOS?

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

    This works on MacOS Mountain Lion (10.8), Solaris 10 (SunOS 5.10) and RHE Linux (Red Hat Enterprise Linux Server release 5.3, Tikanga)...

    $ sed 's/{pattern}/\^J/g' foo.txt > foo2.txt
    

    ... where the ^J is done by doing ctrl+v+j. Do mind the \ before the ^J.

    PS, I know the sed in RHEL is GNU, the MacOS sed is FreeBSD based, and although I'm not sure about the Solaris sed, I believe this will work pretty much with any sed. YMMV tho'...

提交回复
热议问题