How to replace space with comma using sed?

前端 未结 8 702
-上瘾入骨i
-上瘾入骨i 2020-12-30 22:52

I would like to replace the empty space between each and every field with comma delimiter.Could someone let me know how can I do this.I tried the below command but it doesn\

相关标签:
8条回答
  • 2020-12-30 23:20

    If you want the output on terminal then,

    $sed 's/ /,/g' filename.txt
    

    But if you want to edit the file itself i.e. if you want to replace space with the comma in the file then,

    $sed -i 's/ /,/g' filename.txt
    
    0 讨论(0)
  • 2020-12-30 23:23

    I just confirmed that:

    cat file.txt | sed "s/\s/,/g"
    

    successfully replaces spaces with commas in Cygwin terminals (mintty 2.9.0). None of the other samples worked for me.

    0 讨论(0)
提交回复
热议问题