-
-
Save psd/9112117 to your computer and use it in GitHub Desktop.
Reduce accuracy of OS coordinates using regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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