removing an extra column in vim

So I load a csv in vim, and realize I screwed up. I wrote out 2 probabilities instead of one.

 2 100004,0.732524934269992,0.267475065730008
3 100015,0.502454568719362,0.497545431280638
4 100026,0.426691576440626,0.573308423559374
5 100030,0.796236053493448,0.203763946506552
6 100047,0.745809954575253,0.254190045424747
7 100052,0.980561973536192,0.0194380264638075
8 100056,0.86757763360163,0.13242236639837
9 100061,0.580641527965135,0.419358472034865
10 100067,0.487600362330103,0.512399637669897
11 100068,0.336393531503461,0.663606468496539
12 100082,0.582289239857109,0.417710760142891
13 100084,0.234077152161437,0.765922847838563
14 100097,0.252967375901838,0.747032624098162
15 100098,0.121602233424238,0.878397766575762

In vim, to get rid of that extra column, you just type:


This says: “from the first line to the last line, swap anything that’s a comma followed by a bunch of not-commas at the end of the line, for nothing. So it just gets rid of the last column. (This will not work for fancy CSVs with quoted strings with embedded commas as the last field. So sad.

This entry was posted in tech and tagged , , , . Bookmark the permalink.

1 Response to removing an extra column in vim

  1. My suggestion: Answer your phone when you tell me to call you when I get off work! Click

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s