Home > Software design >  Edit .csv file, first column not quoted
Edit .csv file, first column not quoted

Time:08-05

I exported a .csv file that contains mistakes. I have never edited such files, therefore I have no idea how to do it. I've looked up on internet and found nothing of the sort.

Since I'm on mac, I have to used text editor apparently.

I'll show the .csv in the snippet:

Longitude (x),"Latitude (y)","Nom de la Station","ID climatologique","Date/Heure","Année","Mois","Jour","Qualité des Données","Temp max.(°C)","Temp max. Indicateur","Temp min.(°C)","Temp min. Indicateur","Temp moy.(°C)","Temp moy. Indicateur","DJC (°C)","DJC Indicateur","DJR (°C)","DJR Indicateur","Pluie tot. (mm)","Pluie tot. Indicateur","Neige tot. (cm)","Neige tot. Indicateur","Précip. tot. (mm)","Précip. tot. Indicateur","Neige au sol (cm)","Neige au sol Indicateur","Dir. raf. max. (10s deg)","Dir. raf. max. Indicateur","Vit. raf. max. (km/h)","Vit. raf. max. Indicateur"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-01","2022","01","01","","-2,9","","-27,2","","-15,1","","33,1","","0,0","","","M","","M","","M","","","35","","34",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-02","2022","01","02","","-18,9","","-31,4","","-25,2","","43,2","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-03","2022","01","03","","-11,5","","-33,2","","-22,4","","40,4","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-04","2022","01","04","","-9,4","","-13,0","","-11,2","","29,2","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-05","2022","01","05","","","M","","M","","M","","M","","M","","M","","M","","M","","","3","","45",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-06","2022","01","06","","-16,9","","-24,1","","-20,5","","38,5","","0,0","","","M","","M","","M","","","1","","34",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-07","2022","01","07","","-19,5","","-31,1","","-25,3","","43,3","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-08","2022","01","08","","-8,5","","-31,2","","-19,9","","37,9","","0,0","","","M","","M","","M","","","18","","48",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-09","2022","01","09","","","M","","M","","M","","M","","M","","M","","M","","M","","","29","","63",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-10","2022","01","10","","-21,4","","-35,6","","-28,5","","46,5","","0,0","","","M","","M","","M","","","33","","35",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-11","2022","01","11","","-15,6","","-36,7","","-26,2","","44,2","","0,0","","","M","","M","","M","","","18","","48",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-12","2022","01","12","","-11,8","","-32,0","","-21,9","","39,9","","0,0","","","M","","M","","M","","","34","","46",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-13","2022","01","13","","-14,8","","-34,7","","-24,8","","42,8","","0,0","","","M","","M","","M","","","35","","46",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-14","2022","01","14","","-23,9","","-37,2","","-30,6","","48,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-15","2022","01","15","","-23,5","","-39,4","","-31,5","","49,5","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-16","2022","01","16","","-10,5","","-27,1","","-18,8","","36,8","","0,0","","","M","","M","","M","","","19","","40",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-17","2022","01","17","","-9,1","","-19,8","","-14,5","","32,5","","0,0","","","M","","M","","M","","","36","","50",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-18","2022","01","18","","-17,9","","-26,7","","-22,3","","40,3","","0,0","","","M","","M","","M","","","32","","33",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-19","2022","01","19","","-12,5","","-26,1","","-19,3","","37,3","","0,0","","","M","","M","","M","","","32","","49",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-20","2022","01","20","","-23,2","","-32,0","","-27,6","","45,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-21","2022","01","21","","-12,6","","-31,4","","-22,0","","40,0","","0,0","","","M","","M","","M","","","19","","37",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-22","2022","01","22","","-9,1","","-19,6","","-14,4","","32,4","","0,0","","","M","","M","","M","","","30","","54",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-23","2022","01","23","","-19,6","","-30,0","","-24,8","","42,8","","0,0","","","M","","M","","M","","","31","","34",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-24","2022","01","24","","-12,6","","-26,7","","-19,7","","37,7","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-25","2022","01","25","","-21,4","","-35,4","","-28,4","","46,4","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-26","2022","01","26","","-11,8","","-41,2","","-26,5","","44,5","","0,0","","","M","","M","","M","","","20","","51",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-27","2022","01","27","","-7,4","","-24,8","","-16,1","","34,1","","0,0","","","M","","M","","M","","","34","","51",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-28","2022","01","28","","-18,7","","-35,8","","-27,3","","45,3","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-29","2022","01","29","","-12,0","","-28,0","","-20,0","","38,0","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-30","2022","01","30","","-12,3","","-25,2","","-18,8","","36,8","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-01-31","2022","01","31","","-12,0","","-33,3","","-22,7","","40,7","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-01","2022","02","01","","1,6","","-13,4","","-5,9","","23,9","","0,0","","","M","","M","","M","","","18","","59",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-02","2022","02","02","","1,8","","-16,5","","-7,4","","25,4","","0,0","","","M","","M","","M","","","27","","45",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-03","2022","02","03","","-16,5","","-32,6","","-24,6","","42,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-04","2022","02","04","","-17,1","","-36,2","","-26,7","","44,7","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-05","2022","02","05","","-14,0","","-37,5","","-25,8","","43,8","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-06","2022","02","06","","-8,7","","-16,9","","-12,8","","30,8","","0,0","","","M","","M","","M","","","17","","38",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-07","2022","02","07","","-6,3","","-11,1","","-8,7","","26,7","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-08","2022","02","08","","-3,2","","-10,5","","-6,9","","24,9","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-09","2022","02","09","","-0,2","","-11,7","","-6,0","","24,0","","0,0","","","M","","M","","M","","","17","","40",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-10","2022","02","10","","-0,3","","-21,4","","-10,9","","28,9","","0,0","","","M","","M","","M","","","33","","36",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-11","2022","02","11","","-2,3","","-19,2","","-10,8","","28,8","","0,0","","","M","","M","","M","","","35","","49",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-12","2022","02","12","","-19,2","","-34,2","","-26,7","","44,7","","0,0","","","M","","M","","M","","","36","","44",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-13","2022","02","13","","-17,8","","-40,2","","-29,0","","47,0","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-14","2022","02","14","","-14,2","","-38,4","","-26,3","","44,3","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-15","2022","02","15","","-14,0","","-31,6","","-22,8","","40,8","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-16","2022","02","16","","1,8","","-15,2","","-6,7","","24,7","","0,0","","","M","","M","","M","","","15","","38",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-17","2022","02","17","","-0,6","","-19,1","","-9,9","","27,9","","0,0","","","M","","M","","M","","","33","","34",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-18","2022","02","18","","-18,2","","-27,9","","-23,1","","41,1","","0,0","","","M","","M","","M","","","2","","36",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-19","2022","02","19","","-14,4","","-25,8","","-20,1","","38,1","","0,0","","","M","","M","","M","","","35","","54",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-20","2022","02","20","","-5,1","","-19,9","","-12,5","","30,5","","0,0","","","M","","M","","M","","","32","","49",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-21","2022","02","21","","-14,4","","-24,3","","-19,4","","37,4","","0,0","","","M","","M","","M","","","33","","41",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-22","2022","02","22","","-15,9","","-19,9","","-17,9","","35,9","","0,0","","","M","","M","","M","","","6","","40",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-23","2022","02","23","","-13,8","","-29,0","","-21,4","","39,4","","0,0","","","M","","M","","M","","","34","","55",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-24","2022","02","24","","-13,2","","-37,5","","-25,4","","43,4","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-25","2022","02","25","","-10,6","","-30,9","","-20,8","","38,8","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-26","2022","02","26","","-4,3","","-22,1","","-13,2","","31,2","","0,0","","","M","","M","","M","","","22","","63",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-27","2022","02","27","","-7,2","","-25,8","","-16,5","","34,5","","0,0","","","M","","M","","M","","","32","","45",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-02-28","2022","02","28","","-10,9","","-33,1","","-22,0","","40,0","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-01","2022","03","01","","-6,3","","-16,9","","-11,6","","29,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-02","2022","03","02","","-6,5","","-20,7","","-13,6","","31,6","","0,0","","","M","","M","","M","","","34","","40",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-03","2022","03","03","","-12,8","","-31,5","","-22,2","","40,2","","0,0","","","M","","M","","M","","","27","","34",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-04","2022","03","04","","-6,1","","-23,7","","-14,9","","32,9","","0,0","","","M","","M","","M","","","25","","36",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-05","2022","03","05","","-1,8","","-27,9","","-14,9","","32,9","","0,0","","","M","","M","","M","","","16","","31",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-06","2022","03","06","","-1,4","","-6,0","","-3,7","","21,7","","0,0","","","M","","M","","M","","","32","","40",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-07","2022","03","07","","-5,5","","-11,2","","-8,4","","26,4","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-08","2022","03","08","","-1,9","","-20,6","","-11,3","","29,3","","0,0","","","M","","M","","M","","","24","","38",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-09","2022","03","09","","-0,2","","-8,2","","-4,2","","22,2","","0,0","","","M","","M","","M","","","26","","59",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-10","2022","03","10","","-5,4","","-21,7","","-13,6","","31,6","","0,0","","","M","","M","","M","","","24","","41",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-11","2022","03","11","","-3,7","","-28,0","","-15,9","","33,9","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-12","2022","03","12","","-6,3","","-23,6","","-15,0","","33,0","","0,0","","","M","","M","","M","","","35","","53",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-13","2022","03","13","","-6,2","","-24,3","","-15,3","","33,3","","0,0","","","M","","M","","M","","","24","","36",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-14","2022","03","14","","-1,9","","-15,0","","-8,5","","26,5","","0,0","","","M","","M","","M","","","26","","44",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-15","2022","03","15","","1,2","","-20,0","","-9,4","","27,4","","0,0","","","M","","M","","M","","","23","","38",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-16","2022","03","16","","5,3","","-6,3","","-0,5","","18,5","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-17","2022","03","17","","9,6","","0,3","","5,0","","13,0","","0,0","","","M","","M","","M","","","17","","33",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-18","2022","03","18","","5,6","","-3,1","","1,3","","16,7","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-19","2022","03","19","","3,0","","-0,8","","1,1","","16,9","","0,0","","","M","","M","","M","","","9","","37",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-20","2022","03","20","","5,2","","-3,7","","0,8","","17,2","","0,0","","","M","","M","","M","","","33","","47",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-21","2022","03","21","","0,2","","-8,1","","-4,0","","22,0","","0,0","","","M","","M","","M","","","29","","52",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-22","2022","03","22","","3,7","","-12,1","","-4,2","","22,2","","0,0","","","M","","M","","M","","","2","","33",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-23","2022","03","23","","3,1","","-8,3","","-2,6","","20,6","","0,0","","","M","","M","","M","","","10","","41",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-24","2022","03","24","","3,0","","-1,4","","0,8","","17,2","","0,0","","","M","","M","","M","","","10","","48",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-25","2022","03","25","","1,8","","-0,4","","0,7","","17,3","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-26","2022","03","26","","1,0","","-13,5","","-6,3","","24,3","","0,0","","","M","","M","","M","","","32","","49",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-27","2022","03","27","","-13,5","","-18,3","","-15,9","","33,9","","0,0","","","M","","M","","M","","","33","","44",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-28","2022","03","28","","-8,0","","-18,6","","-13,3","","31,3","","0,0","","","M","","M","","M","","","30","","39",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-29","2022","03","29","","-1,7","","-22,1","","-11,9","","29,9","","0,0","","","M","","M","","M","","","30","","40",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-30","2022","03","30","","2,4","","-18,4","","-8,0","","26,0","","0,0","","","M","","M","","M","","","13","","42",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-03-31","2022","03","31","","6,6","","-5,1","","0,8","","17,2","","0,0","","","M","","M","","M","","","22","","72",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-01","2022","04","01","","-0,8","","-11,2","","-6,0","","24,0","","0,0","","","M","","M","","M","","","30","","42",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-02","2022","04","02","","5,1","","-14,4","","-4,7","","22,7","","0,0","","","M","","M","","M","","","22","","35",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-03","2022","04","03","","4,3","","-6,0","","-0,9","","18,9","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-04","2022","04","04","","7,3","","-8,0","","-0,4","","18,4","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-05","2022","04","05","","9,7","","-5,0","","2,4","","15,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-06","2022","04","06","","11,3","","-1,6","","4,9","","13,1","","0,0","","","M","","M","","M","","","8","","49",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-07","2022","04","07","","8,3","","1,2","","4,8","","13,2","","0,0","","","M","","M","","M","","","10","","59",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-08","2022","04","08","","8,1","","-1,3","","3,4","","14,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-09","2022","04","09","","1,5","","-3,4","","-1,0","","19,0","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-10","2022","04","10","","3,8","","-5,0","","-0,6","","18,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-11","2022","04","11","","9,5","","-6,8","","1,4","","16,6","","0,0","","","M","","M","","M","","","14","","47",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-12","2022","04","12","","10,8","","-2,5","","4,2","","13,8","","0,0","","","M","","M","","M","","","24","","60",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-13","2022","04","13","","4,6","","-3,9","","0,4","","17,6","","0,0","","","M","","M","","M","","","","M","","M"
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-14","2022","04","14","","8,4","","-1,3","","3,6","","14,4","","0,0","","","M","","M","","M","","","23","","64",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-15","2022","04","15","","3,2","","-4,3","","-0,6","","18,6","","0,0","","","M","","M","","M","","","24","","53",""
-78,84,"48,21","ROUYN-NORANDA A","7086719","2022-04-16","2022","04","16","","1,9","","-4,1","","-1,1","","19,1","","0,0","","","M","","M","","M","","","28","","33",""

If someone could help me with that, it would be very much appreciated !

CodePudding user response:

It actually depends on what the mistakes in the csv file are. If for example you wanted to change the decimal separator from "," to "." you could use the command line tool sed with a regular expression

cat data.csv | sed '2,$s/"\(-\?[0-9]\ \),\([0-9]\ \)"/\1.\2/g' | sed '2,$s/^\(-\?[0-9]\ \),\([0-9]\ \)/\1.\2/'

CodePudding user response:

This is inelegant, but it works for all the lines that start with a numeric:

while read ln; do echo $ln |sed '/^-/s/^/"/' | sed 's/,/",/2' >> new.csv; done < test.csv

For the header line, you'd have to manually add the second double-quote, or use a separate sed iteration.

  • Related