Hi Dave,
grep -o and use a regular expression to find <name id=\"AAAAAAA then use
bash ${string#substring} to trim off the <name id=
(treat this as metacode - I've not run it at all and it's probably not
syntactically correct)
#!/bin/bash
wget --whatever-options-you-want
http://some.location.com/some/loc/file --output to "/tmp/geocaching.loc"
LOC="/tmp/geocaching.loc"
GPX=${`grep --only-matching --regexp=/<name id=\"[A-Z0-9]{6}/
$LOC`#<name id=\"}
# note the back-quotes around the grep
gpsbabel -i geo -f $LOC -o gpx -F ~/$GPX.gpx && gpsbabel -w -i gpx -f
$GPX.gpx -o garmin -F /dev/ttyS0 && rm $LOC # changed & to && in
case a step fails it won't delete the input file
Might be a way to adjust the regex so as to match against <name
id=\"AAAAAAA and only return the AAAAAAA
An alternative and more more classic way would be to replace the grep
call with a similar one to sed to pull the AAAAAAA directly out of your
file.
Euan Clark
Dave G wrote:
Firstly it may be that grep isn't the way to go here but ...
Currently I'm downloading .loc files from Geocaching.com, converting
them to .gpx format, rename them to the correct waypoint name and
uploading them to the GPS,
finally deleting the old .loc file (as they have a generic name -
geocaching.loc)
(I should mention here that I've been doing this for ages using VMWare
etc. etc. but I'm keen to explore some good old "nix" options)
I can do all the steps manually no worries but what I'm trying to
write a bash script to automate this a bit
What I'm wanting to do is grab a string of characters from a GPS (.loc
- xml?)
file and use that string to rename that file from the generic name to
the specific waypoint name, convert it to .gpx & upload it
I've been doing a power-of-googling tonight but I haven't got it to
work yet
here are the manual steps I'm currently using (which work):
1. download .loc file to /tmp
2. open the .loc file and manually, copy the waypoint name then paste
it into the following code (convert the Geocaching .loc file to .gpx
format, then delete the .loc file):
3. Code: gpsbabel -i geo -f /tmp/geocaching.loc -o gpx -F
~/<insert-Geocache-name>.gpx & rm /tmp/geocaching.loc
4. finally upload the waypoint to the GPS:
5. Code: gpsbabel -w -i gpx -f <insert-Geocache-name>.gpx -o garmin
-F /dev/ttyS0
It works quite well but isn't very elegant I'm afraid
Heres a sample of a .loc file:
<?xml version="1.0" encoding="UTF-8"?>
<loc version="1.0" src="Groundspeak">
<waypoint>
<name id="GCW0FP"><![CDATA[Tasty Baking (Canterbury) by
BuckoBoys]]></name>
<coord lat="-43.***" lon="172.***"/>
<type>Geocache</type>
<link text="Cache
Details">http://www.geocaching.com/seek/cache_details.aspx?wp=GCW0FP</link>
</waypoint></loc>
The bit I want out is: "GCW0FP" so I end up with the file "GCW0FP.gpx"
being uploaded (limited to 6 characters - numbers/letters all uppercase)
Thanks in advance