Skip to content

Instantly share code, notes, and snippets.

@amitpdev
Created September 16, 2015 17:17
Show Gist options
  • Save amitpdev/8a61cf1f4a43973e570b to your computer and use it in GitHub Desktop.
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.
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
@kalidasweb
Copy link

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 👍 ).

@pappalar
Copy link

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