2

I am trying to simulate a path in Xcode which has speed, latitude and longitude information.

There is a site which produces the same: http://www.bikehike.co.uk/mapview.php

I found one awk script which can convert this file to Xcode acceptable format: https://gist.github.com/scotbond/8a61cf1f4a43973e570b

Tried running this command in the terminal: awk -F script.awk bikehike_course >output.gpx

Where script.awk has the script, bikehike_course has the GPX file and output.gpx is the output file name

UPDATE

Tried: awk -f script.awk bikehike_course > output.gpx

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

I think the syntax of the GPS file is broken.

nr5
  • 4,228
  • 8
  • 42
  • 82
  • 1
    I'm missing your actual problem. Btw. `-F` and `-f` are different options in awk with distinct meanings. You probably wanted to use `-f` (to denote the awk script file) but `-F` specifies the field separators instead. – Scheff's Cat Jun 02 '17 at 05:54
  • @Scheff tried with `-f` but got syntax error in the file. Question updated, have a look. – nr5 Jun 02 '17 at 06:47
  • I cannot see something wrong in line 3 nor line 24. My first try would be to check for line ending issues in the script text. I.e. ensure that script has the correct line-endings like required in IOS. – Scheff's Cat Jun 02 '17 at 06:52
  • @Scheff I think the text got edited. I copied the text from git and tried again, but different error this time. Update the question, have a look. – nr5 Jun 02 '17 at 06:55
  • 1
    I got it. You're scipt at github contains a complete awk **call**. Thus, either you call it directly in bash (should rename it to `adjust_gpx_to_apple_format.sh`) or you remove `awk '` at begin and `' $1` at end. – Scheff's Cat Jun 02 '17 at 06:58
  • 1
    As it is currently on github it's a _shell_ script which calls awk with the awk script provided as parameter. Thus, the suffix `.awk` is somehow misleading. (And `awk -f adjust_gpx_to_apple_format.awk` will not work as it expects _awk_ syntax but not _shell_ syntax.) – Scheff's Cat Jun 02 '17 at 07:05
  • ok so finally this worked: "awk -f adjust_gpx_to_apple_format.awk bikehike_course.gpx > output.gpx". I removed the `awk '` and `' $1` from the file. Thanks. Since you seems to know about this, could you point me in some direction where I can lear to write my own regex and also this awk. I am new to this. And you can answer my question, I'll mark it as answer :) – nr5 Jun 02 '17 at 07:15
  • 1
    awk is really an old tool. Try simply google "awk tutorial" and choose the one that you like most. Consider that GNU awk (gawk) is currently wide spread (as it provides some convenient and useful extensions) but I recognized issues on OSX where it is not the default. – Scheff's Cat Jun 02 '17 at 07:26
  • Perhaps you can try GPSBabel, I have posted an answer in another question, https://stackoverflow.com/questions/43428073/gpx-file-does-not-load-ios-xcode/44383838#44383838. Hope it can help. – hzm Jun 06 '17 at 07:33

1 Answers1

2

The script on adjust_gpx_to_apple_format.awk on github is a call of awk with the awk script provided as parameter (in shell syntax).

Thus, the name adjust_gpx_to_apple_format.awk is somehow misleading.

Either the awk ' at the beginning and ' $1' at the end has to be removed. In this case,

awk -f adjust_gpx_to_apple_format.awk

should work (as the script looks like a correct awk script otherwise).

If left as is, the script might be called directly in the shell:

> ./adjust_gpx_to_apple_format.awk input.txt >output.txt

In the latter case, I would suggest two additions:

  1. Insert a "hut" in the first line e.g. #!/bin/bash which makes it more obviously.

  2. Rename the script to adjust_gpx_to_apple_format.sh.

Note: Remember, that the file suffix does not have the strict meaning in Unix like shells as they have for example in MSDOS. Actually, the suffix could be anything (including nothing). It's more valuable for the user than the shell and should be chosen respectively.

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
  • I got another problem now. I was using this GPX file to simulate in the iPhone simulator. XCode has a certain requirement: "Waypoint must specify a later time than the previous waypoint". I think I'll have to find a different GPX file, which provides different time for every way point or somehow change the one which I get from bikehike.co.uk – nr5 Jun 02 '17 at 07:47
  • There is a description on Wikipedia [GPS Exchange Format](https://en.wikipedia.org/wiki/GPS_Exchange_Format) which seems to be a good start. In case, you may start a new (specific) question on this topic. (Sorry, I don't know anything about OSX, IOS, or IPhone nor GPS data. My note about awk on OSX was based on the feed back I got from OSX users when providing my answers which I had checked and considered to be well working on "my" Windows/cygwin in GNU awk.) – Scheff's Cat Jun 02 '17 at 08:16
  • How about to edit your question and include the not working GPX file (or at least a part of it). May be, your awk script could be extended to fix/tweak the ` – Scheff's Cat Jun 02 '17 at 08:24