Search code examples
pythoncsvvim

remove one comma using a python script


I have csv file with a line that looks something like this:

,,,,,,,,,,

That's 10 commas. I wish to remove only the last (i.e. the 10th) comma, so that the line changes to:

,,,,,,,,,

Has anyone had any experience dealing with a case like this? I use the vim text editor also. So, any help using python script or text editing commands using vim would be appreciated.


Solution

  • Removing last comma in current line in vim: :s/,$//

    The same for lines n through m: :n,ms/,$//

    The same for whole file: :%s/,$//