I have a number of csv files that have differing numbers of commas per line in each of them. I would like to remove any commas past 6 in a line but if there are only 6 commas, then leave the line alone.
This regex removes extra commas if there are more than 6:
^([^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*),(.*)$
and replace with
\1\2
The problem I am running into is if I run this against all files, if it finds a line with only six commas, it will move and include the next line. How do I restrict this to each single line?
Thanks everyone.
Example:
c1,c2,c3,c4,c5,c6,c7
asdf,asdf,asdf,asdf,asdf,asdf,asdf
asdf,asdf,asdf,asdf,asdf,asdf,asdf,,,asdf,asdf
asdf,asdf,asdf,asdf,asdf,asdf,asdf,,
I would like to end up with this:
c1,c2,c3,c4,c5,c6,c7
asdf,asdf,asdf,asdf,asdf,asdf,asdf
asdf,asdf,asdf,asdf,asdf,asdf,asdfasdfasdf
asdf,asdf,asdf,asdf,asdf,asdf,asdf