Replace comma with newline in sed on MacOS?

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

    sed on macOS Mojave was released in 2005, so one solution is to install the gnu-sed,

    brew install gnu-sed
    

    then use gsed will do as you wish,

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

    If you prefer sed, just sudo sh -c 'echo /usr/local/opt/gnu-sed/libexec/gnubin > /etc/paths.d/brew', which is suggested by brew info gnu-sed. Restart your term, then your sed in command line is gsed.

提交回复
热议问题