How to replace space with comma using sed?

前端 未结 8 811
-上瘾入骨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 22:56

    IF your data includes an arbitrary sequence of blank characters (tab, space), and you want to replace each sequence with one comma, use the following:

    sed 's/[\t ]+/,/g' input_file
    

    or

    sed -r 's/[[:blank:]]+/,/g' input_file
    

    If you want to replace sequence of space characters, which includes other characters such as carriage return and backspace, etc, then use the following:

    sed -r 's/[[:space:]]+/,/g' input_file
    

提交回复
热议问题