Created
September 16, 2015 17:17
-
-
Save amitpdev/8a61cf1f4a43973e570b to your computer and use it in GitHub Desktop.
Use this awk script to adjust standard GPX files downloaded from any site (bikes) into a GPX format that is supported by Xcode.
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
awk ' | |
BEGIN { | |
buffer="" | |
} | |
{ | |
gsub(/<\/*trk>/,"",$0) | |
gsub(/<\/*trkseg>/,"",$0) | |
gsub(/<trkpt/,"<wpt", $0) | |
gsub(/<\/trkpt>/,"<\/wpt>", $0) | |
} | |
/<wpt/,/<\/wpt>/ { | |
buffer=buffer $0 | |
if ($0 !~ "<\/wpt>") { | |
buffer=buffer "\n" | |
} | |
} | |
/<\/wpt>/ { | |
#print buffer | |
buffer="" | |
} | |
END { | |
}' $1 |
OK, I tried: "awk -f script.awk bikehike_course > output.gpx", but got this error:
Error: awk: syntax error at source line 1 source file adjust_gpx_to_apple_format.awk context is awk >>> ' <<< awk: bailing out at source line 24
awk
BEGIN {
buffer=""
}
{
gsub(/<\/*trk>/,"",$0)
gsub(/<\/*trkseg>/,"",$0)
gsub(/<trkpt/,"<wpt", $0)
gsub(/<\/trkpt>/,"<\/wpt>", $0)
print
}
/<wpt/,/<\/wpt>/ {
buffer=buffer $0
if ($0 !~ "<\/wpt>") {
buffer=buffer "\n"
}
}
/<\/wpt>/ {
#print buffer
buffer=""
}
END {
} $1
this one working fine just remove some codes :) (crazy only single quotes 👍 ).
All the buffer calculation is not needed.
The same effect can be achieved by editing the original file and printing the result (which is what the script is already doing, but by using print is printing twice the same things)
awk
{
gsub(/<\/*trk>/,"",$0)
gsub(/<\/*trkseg>/,"",$0)
gsub(/<trkpt/,"<wpt", $0)
gsub(/<\/trkpt>/,"<\/wpt>", $0)
}
END {}
$1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not sure how to process the file from bikehike with this script. Can you help. I tried with terminal in Mac but no luck.