convert to target csv format
This commit is contained in:
parent
45d2eddb26
commit
f80dde2487
|
@ -1,2 +1,3 @@
|
|||
*.csv
|
||||
baerer
|
||||
*.bak
|
||||
|
|
33
dhl.sh
33
dhl.sh
|
@ -1,13 +1,24 @@
|
|||
#!/usr/bin/env sh
|
||||
dependencies="sed test cp libreoffice"
|
||||
assert_tools () {
|
||||
while test $# -gt 0; do
|
||||
which $1 >/dev/null 2>/dev/null || {
|
||||
echo "tool missing: "$1
|
||||
exit 2
|
||||
}
|
||||
shift
|
||||
done
|
||||
}
|
||||
assert_tools ${dependencies}
|
||||
|
||||
# target filename
|
||||
tn="dhl-ds-versendung.csv"
|
||||
tn="dhl-cp1252.csv"
|
||||
|
||||
# todo: download file (its UTF-8 encoded)
|
||||
|
||||
fn="dhl-ds-versendung-3.csv"
|
||||
fn="dhl.csv"
|
||||
# backup
|
||||
cp -f "$fn" "dhl.csv"
|
||||
cp -f "${fn}" "${fn}.bak"
|
||||
|
||||
# replace special spaces and hyphens
|
||||
sed -i -e 's/[\u00A0\u202F[:space:]]+/ /g' -e 's/[\u2010\u2011\u2012\u2013\u002D]+/-/g' -e 's/[\u00AD\uFEFF]+//g' "$fn"
|
||||
|
@ -77,3 +88,19 @@ testiso3 () {
|
|||
testcmp "" "iso3countrycode" "Simbabwe" # should fail
|
||||
}
|
||||
#~ testiso3
|
||||
|
||||
convcsv () {
|
||||
if test $# -eq 0 ; then echo "argument missing."; exit 1; fi
|
||||
if test -e $1 ; then echo "file already exists."; exit 2; fi
|
||||
# charset windows codepage 1252
|
||||
# doc for headless conversion options https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
|
||||
if="${1}"
|
||||
of=$(echo "${if}"|rev|cut -d. -f2-|rev)".ods"
|
||||
libreoffice --headless --convert-to ods --infilter=CSV:59,34,76,1 "${if}" && {
|
||||
mv "${if}" "${if}.bak"
|
||||
libreoffice --headless --infilter=CSV:59,34,76,1 --convert-to csv:"Text - txt - csv (StarCalc)":"44,34,1,0,1,,0" "${tf}" && {
|
||||
rm "${tf}" "${if}.bak"
|
||||
}
|
||||
}
|
||||
}
|
||||
convcsv "$fn"
|
||||
|
|
Loading…
Reference in New Issue