From 28d6e80db08f44a0a0c822a30d4b83e6312e5b85 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 28 Jan 2019 11:43:57 +0100 Subject: Try to make accessing filenames with spaces more robust --- makecolumns.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/makecolumns.sh b/makecolumns.sh index c38a791..4920550 100755 --- a/makecolumns.sh +++ b/makecolumns.sh @@ -77,12 +77,12 @@ do_processfile_version_3() { } size() { - stat -f %z `printf %0${filename_len}d $1` + stat -f %z `printf %0${filename_len}d "$1"` } get_dword() { # $1 file - hexdump -n 4 -v -e '" " 1/4 "%u"' `printf %0${filename_len}d ${1}` + hexdump -n 4 -v -e '" " 1/4 "%u"' `printf %0${filename_len}d "${1}"` } handle_format_version_1() { @@ -165,7 +165,7 @@ handle_format_version_2() { handle_format_version_3() { echo "Working on $1. Detected pre-2004 Telefonbuch version." # Extract teiln.dat - do_decompress_version_3 $1/[Dd][Aa][Tt]/[Tt][Ee][Ii][Ll][Nn].[Dd][Aa][Tt] "teiln.dat" + do_decompress_version_3 "$1/[Dd][Aa][Tt]/[Tt][Ee][Ii][Ll][Nn].[Dd][Aa][Tt]" "teiln.dat" # See how long each filename is export filename_len=$(( `ls | head -n 1 | wc -c` - 1 )) @@ -251,7 +251,7 @@ handle_format_version_3() { # If street names come in an extra file, extract # street names first - streets=$1/[Dd][Aa][Tt]/[Ss][Tt][Rr][Aa][Ss][Ss][Ee][Nn].[Dd][Aa][Tt] + streets="$1/[Dd][Aa][Tt]/[Ss][Tt][Rr][Aa][Ss][Ss][Ee][Nn].[Dd][Aa][Tt]" [ -f ${streets} ] && do_processfile_version_3 ${streets} "street name" 99_Strassenname convert_zeros # extract street names if 07_unknown contains street indexes @@ -272,7 +272,7 @@ handle_format_version_3() { tidy_streetnames 07_Strasse fi - karto=$1/[Dd][Aa][Tt]/[Kk][Aa][Rr][Tt][Oo].[Dd][Aa][Tt] + karto="$1/[Dd][Aa][Tt]/[Kk][Aa][Rr][Tt][Oo].[Dd][Aa][Tt]" if [ -f ${karto} ]; then do_processfile_version_3 ${karto} "geo coordinates" 90_Geokoordinaten_hnr_raw @@ -285,7 +285,7 @@ handle_format_version_3() { } handle_format_version_4() { - if [ -f $1/branchcodes.tl ]; then + if [ -f "$1/branchcodes.tl" ]; then is_yp=true echo "Working on $1. Detected post-2003 Yellow Pages version." else @@ -294,14 +294,14 @@ handle_format_version_4() { fi printf "Extracting street names ... " - extract_version_4 $1/streets.tl + extract_version_4 "$1/streets.tl" cat file_* | tr '\n\0' '\t\n' > 99_Strassenname rm file_* printf "done.\n" printf "Extracting phonebook.db ... " - extract_version_4 $1/phonebook.db + extract_version_4 "$1/phonebook.db" rows=`find . -name file_\* | wc -l` printf "done.\n" @@ -353,17 +353,17 @@ handle_format_version_4() { tr '\t' ' ' < 04_05_Namenszusatz_Addresszusatz | sed -E s/' +'/' '/g > 04_Zusaetze printf "done.\n" - if [ -f $1/zip-streets-hn-geo.tl ]; then + if [ -f "$1/zip-streets-hn-geo.tl" ]; then printf "Extracting geo coordinates (precision: house number) ... " - extract_version_4 $1/zip-streets-hn-geo.tl + extract_version_4 "$1/zip-streets-hn-geo.tl" cat file_* > 90_Geokoordinaten_hnr printf "done.\n" printf "Looking up geo coordinates for each phonebook entry ... " paste 10_Postleitzahl 07_Strasse 08_Hausnummer | map_coords 90_Geokoordinaten_hnr | convert_coords > 16_Koordinaten printf "done.\n" - elif [ -f $1/zip-streets-geo.tl ]; then + elif [ -f "$1/zip-streets-geo.tl" ]; then printf "Extracting geo coordinates (precision: street) ... " - extract_version_4 $1/zip-streets-geo.tl + extract_version_4 "$1/zip-streets-geo.tl" cat file_* > 91_Geokoordinaten_str printf "done.\n" printf "Looking up geo coordinates for each phonebook entry ... " @@ -374,7 +374,7 @@ handle_format_version_4() { if [ "${is_yp}" ]; then printf "Extracting branch names ... " - extract_version_4 $1/branchcodes.tl + extract_version_4 "$1/branchcodes.tl" cat file_* | tr '\n\0' '\t\n' > 97_Branchenname rm file_* printf "done.\n" @@ -394,7 +394,7 @@ handle_format_version_4() { } tidy_streetnames () { - streets=$1 + streets="$1" # Replace any dots at end of line by a single one # finish any str abbreviation without a period with a period -- cgit v1.2.3