Skip to content

Instantly share code, notes, and snippets.

@psd
Last active August 29, 2015 13:56
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 psd/9112117 to your computer and use it in GitHub Desktop.
Save psd/9112117 to your computer and use it in GitHub Desktop.
Reduce accuracy of OS coordinates using regex
#!/bin/bash
let tests=0
let fails=0
while read ngr expected
do
let tests=tests+1
out=$(echo $ngr | gawk '{
$1 = gensub(/^(..)([0-9][0-9])...([0-9][0-9])...$/, "\\1\\2\\3", "", $1);
$1 = gensub(/^(..)([0-9][0-9])..([0-9][0-9])..$/,"\\1\\2\\3", "", $1);
$1 = gensub(/^(..)([0-9][0-9]).([0-9][0-9]).$/,"\\1\\2\\3", "", $1);
print $1
}')
if [ "$out" = "$expected" ]
then
echo "OK: $ngr got $out"
else
echo "FAIL: $ngr got $out expected $expected" >&2
let fails=fails+1
fi
done <<-!
TL1234567890 TL1267
TL12345678 TL1256
TL123456 TL1245
TL1234 TL1234
!
echo "$tests TESTS. $fails FAILURE(S)"
[ $fails -ne 0 ] && exit 1
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment