使用VIM用逗号分隔所有IP:端口值

时间:2017-06-29 14:01:41

标签: vim

我有一个数据文件,它包含如下所示的日志条目:

  2011-08-17,12:01:01.813,0.000,UDP,82.117.234.33:23989,147.32.86.165:12114,INT,0,1,71,1,Background
  2011-08-17,12:01:01.813,0.075,UDP,147.32.84.118:1153,91.225.21.243:35691,INT,0,1,143,1,Background
  2011-08-17,12:01:01.813,0.000,UDP,147.32.86.165:12114,82.117.234.33:23989,INT,0,1,61,1,Background
  2011-08-17,12:01:01.816,1.999,UDP,119.30.39.65:42343,147.32.84.229:13363,INT,0,4,1442,1,Background
  2011-08-17,12:01:01.816,1.999,UDP,147.32.84.229:13363,119.30.39.65:42343,INT,0,4,244,1,Background
  ...

我想用Pandas解析它,并且还将所有port-value作为单独的列获取。为此,所有IP:端口条目82.117.234.33:23989都应转换为82.117.234.33,23989。这在VIM中是否可行?

我知道我可以使用以下命令%s/:/,/gc用逗号替换所有:值,但这会破坏我的时间戳。

1 个答案:

答案 0 :(得分:4)

可以使用\d\+匹配数字组:

%s/\(\d\+\.\d\+\.\d\+\.\d\+\):\(\d\+\),/\1,\2,/g