在每3个字符串后用空格替换逗号

时间:2016-03-02 15:19:02

标签: mysql regex csv sed

我有一个csv文件,如下所示:

"user1","track1","player1","user1","track2","player2","user1","track3","player3",........

我需要做的是用空格(不是所有的逗号)替换逗号,只删除playerIds之后的逗号(指定一行,以便稍后将它们导入Mysql)。所以,我需要结果如下:

"user1","track1","player1" "user1","track2","player2" "user1","track3","player3" ........

我发现我们可以用空格sed替换逗号:

sed 's/,/ /g' output.csv >output2.csv

然而,它用空格替换所有逗号..我不知道如何在每3个字符串后才能这样做。任何的想法?

谢谢,

1 个答案:

答案 0 :(得分:1)

您可以像这样使用sed

sed -E 's/(([^,]*,){2}[^,]*),/\1 /g' file

"user1","track1","player1" "user1","track2","player2" "user1","track3","player3"