BlogBlog ÜbersichtjailscriptportsoptFreeBSDLinksThermoskanne

Zwei CSV-Dateien miteinander vergleichen

Mit Hilfe von csvdiff lassen sich zwei CSV-Dateien vergleichen und deren Unterschiede übersichtlich darstellen. Im FreeBSD Portbaum findet man csvdiff unter textproc/csvdiff:

# cd /usr/ports/textproc/csvdiff && make install clean

Mit der -e Option wird die ursprüngliche, mit der -a Option die veränderte CSV-Datei angegebenen. Möchte man die Spaltennamen anzeigen lassen, erstellt man eine weitere CSV-Datei in der auf einer Zeile die Spaltennamen aufgeführt sind. Diese Datei kann danach mit der -c Option an csvdiff übergeben werden. Standardmässig wird als Trennzeichen ein Komma verwendet, möchte man ein anderes Trennzeichen angeben, kann dies mit der -s Option gemacht werden:

# /usr/local/bin/csvdiff -e kalender.csv -a kalender_neu.csv -c spalten.csv

-------------------------------------------------------------------------------

Record no: 002 is different:
 Actual   line: "1","11/26/05","07:00:00 am","11/27/05","10:00:00 pm","False","False","","","null","null","null","True"
 Expected line: "1","11/26/05","08:00:00 am","11/27/05","10:00:00 pm","False","False","","","null","null","null","True"
  Difference in field no.: 03 - field name: "Start Time"
   Actual  : "07:00:00 am"
   Expected: "08:00:00 am"

-------------------------------------------------------------------------------

Record no: 106 is different:
 Actual   line: "3","11/10/06","01:00:00 am","11/13/06","01:00:00 am","False","False","","","null","","Mailand","True"
 Expected line: "3","11/10/06","01:00:00 am","11/13/06","01:00:00 am","True","False","","","null","","Mailand","True"
  Difference in field no.: 06 - field name: "All day event"
   Actual  : "False"
   Expected: "True"

-------------------------------------------------------------------------------

Record no: 306 is different:
 Actual   line: "6","10/18/08","12:00:00 am","10/20/08","12:00:00 am","True","False","","","null","null","null","True"
 Expected line: "6","10/18/08","12:00:00 am","10/20/08","12:00:00 am","True","False","","","null","null","null","False"
  Difference in field no.: 13 - field name: "Private"
   Actual  : "True"
   Expected: "False"

-------------------------------------------------------------------------------

Record no: 401 is different:
 Actual   line: "E","09/17/09","12:00:00 am","09/21/09","12:00:00 am","True","False","","","null","null","null","False"
 Expected line: "e","09/17/09","12:00:00 am","09/21/09","12:00:00 am","True","False","","","null","null","null","False"
  Difference in field no.: 01 - field name: "Subject"
   Actual  : "E"
   Expected: "e"

===============================================================================

Following lines exists only in actual result kalender_neu.csv:

-------------------------------------------------------------------------------

 Actual 412 line 413 : "Fut","??/??/10","","","","True","False","","","null","null","null","True"

Mehr Informationen und weitere Optionen zu csvdiff erhält man mit der -h Option:

# csvdiff -h
 Permalink