Skip to content

Instantly share code, notes, and snippets.

@sedrubal
Created May 14, 2023 11:14
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 sedrubal/e513465686d1bde279c131f769a5933d to your computer and use it in GitHub Desktop.
Save sedrubal/e513465686d1bde279c131f769a5933d to your computer and use it in GitHub Desktop.
Clean Fahrradverkehrsdaten from offenedaten-koeln.de
for f in *.csv; do
new_file_name=$(echo $f | cut -d'_' -f 4 | cut -d' ' -f 6)
echo $new_file_name
encoding=$(file -N --mime-encoding "${f}" | cut -d':' -f2)
iconv -f ${encoding} -t utf-8 "${f}" |
sed 's/^M\+$//' |
sed 's/\.//g' |
sed -r 's/Jan(uar| [0-9]+)/01/;s/Feb(ruar| [0-9]+)/02/;s/(März|Mrz [0-9]+)/03/;s/Apr(il| [0-9]+)/04/;s/Mai(| [0-9]+)/05/;s/Jun(i| [0-9]+)/06/;s/Jul(i| [0-9]+)/07/;s/Aug(ust| [0-9]+)/08/;s/Sep(tember| [0-9]+)/09/;s/Okt(ober| [0-9]+)/10/;s/Nov(ember| [0-9]+)/11/;s/Dez(ember| [0-9]+)/12/' |
sed -r 's/Jahr [0-9]+//' |
sed 's/Jahressumme.*$//' > "${new_file_name}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment