Skip to content

Instantly share code, notes, and snippets.

@xoquox
Last active February 16, 2023 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoquox/c107cc153a2a79ff846f8b83d6ab9875 to your computer and use it in GitHub Desktop.
Save xoquox/c107cc153a2a79ff846f8b83d6ab9875 to your computer and use it in GitHub Desktop.
A short Miller script for converting to Shopify oders_export.csv to the Hermes (Germany) CSV format for address import.
#!/bin/bash
mlr --csv --ofs ';' put '
if ($Shipping\ Name =~ "(\\S+)\\s+(\\S+)$") {
$Vorname\ (20) = sub($Shipping\ Name, "(\\S+)\\s+(\\S+)$", "\\1");
$Nachname/Firmenname\ (30) = sub($Shipping\ Name, "(\\S+)\\s+(\\S+)$", "\\2");
};
$Hausnummer\ (5) = sub($Shipping\ Address1, "\\D*(\\d+).*", "\\1");
$Strasse\ (27) = sub($Shipping\ Address1, "(.*)\\d+.*", "\\1");
$PLZ\ (10) = $Shipping\ Zip;
$Ort\ (30) = $Shipping\ City;
$Adresszusatz\ (50) = $Shipping\ Address2;
$Kundenreferenznummer\ (20) = $Name;
$Tel.\ Vorwahl\ (6) = "";
$Telefonnummer\ (14) = "";
$E-Mail-Adresse\ (70) = "";
$Paketklasse = "";
$Sperrgutkennzeichen = "0";
$Nachnahmebetrag = "";
$Zusatzinformation = "";
cut -o -f "Vorname (20)","Nachname/Firmenname (30)","Adresszusatz (50)","Strasse (27)","Hausnummer (5)","PLZ (10)","Ort (30)","Tel. Vorwahl (6)","Telefonnummer (14)","E-Mail-Adresse (70)","Kundenreferenznummer (20)","Paketklasse","Sperrgutkennzeichen","Nachnahmebetrag","Zusatzinformation"
' orders_export.csv
#!/bin/bash
mlr --csv --ofs ';' filter '${Shipping Name} != ""' \
then put '${Vorname (20)} = regextract(${Shipping Name},"([^\s]+)"); ${Nachname/Firmenname (30)} = regextract(${Shipping Name}, "(\S+)$"); ${Hausnummer (5)} = regextract(${Shipping Address1}, "\d+"); ${Strasse (27)} = regextract(${Shipping Address1}, "\D+")' \
then put '${Tel. Vorwahl (6)} = ""; ${Telefonnummer (14)} = ""; ${E-Mail-Adresse (70)} = ""; $Paketklasse = ""; $Sperrgutkennzeichen = "0"; $Nachnahmebetrag = ""; $Zusatzinformation = ""' \
then rename 'Shipping Zip','PLZ (10)','Shipping City','Ort (30)','Name','Kundenreferenznummer (20)','Shipping Address2','Adresszusatz (50)' \
then cut -o -f 'Vorname (20)','Nachname/Firmenname (30)','Adresszusatz (50)','Strasse (27)','Hausnummer (5)','PLZ (10)','Ort (30)','Tel. Vorwahl (6)','Telefonnummer (14)','E-Mail-Adresse (70)','Kundenreferenznummer (20)','Paketklasse','Sperrgutkennzeichen','Nachnahmebetrag','Zusatzinformation' \
orders_export.csv
@xoquox
Copy link
Author

xoquox commented Nov 13, 2022

Comments:

  • In the first line (line 3) I exclude all empty entrys
  • In line 4 I split up pre name and last name, also the street and number. The later one isn't really necessary, cause Hermes accepts also Street and number in one field.
  • In line 5 I add some missing fields, you could also compute the "Paketklasse" from the Shopify export if you want.
  • In line 6 I rename some fields
  • In line 7 I tell miller which fields I want in my new CSV, and at which position.

Some notes:

  • the script doesn't write the output to a file right now, to do so, you have to add a "> your_export_file_name.csv" at the end. I didn't do right now, cause then it strangely doesn't work at my machine anymore.
  • I don't convert the eMail and phonenumber, but you can, just remove ${Telefonnummer (14)} = ""; ${E-Mail-Adresse (70)} = ""; and add to line 6 'Email','E-Mail-Adresse (70)','Billing Phone','Telefonnummer (14)'. You have also to add to line 7 'E-Mail-Adresse (70)',Telefonnummer (14)
  • right now it is only for the NATIONAL format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment