Re: Basic scripting
Stephen Gregory <[email protected]>
| Newsgroups | gmane.user-groups.linux.ottawa.general |
|---|---|
| Message-ID | <[email protected]> |
Damian Gerow wrote:
> -----
> #!/bin/sh
>
> # There's a better way to do this. It's called 'awk'.
> LATITUDE=$(egrep '^Latitude:' ${MESSAGE} | sed 's/^.*://')
> LONGITUDE=$(egrep '^Longitude:' ${MESSAGES} | sed 's/^.*://')
>
> echo "svAdena ${LATITUDE} ${LONGITUDE} waypoint 0 0 0 0" >> way.txt
> -----
Something like this might work
awk -F: ' /^Latitude:/ { LAT=$2 }
/^Longitude:/ { LONG=$2 }
END { print "svAdena " , LAT , LONG , "waypoint 0 0 0 0" } '
>> way.txt
This awk script assumes a lot about the format of the message. It
doesn't check that the lat and long data are numbers or in a good format
etc. I split the awk line onto multiple lines for readability. You
could pipe the message body directly with procmail, or use something
like the following in a bash script.
awk '...' < message.txt >> message.txt
awk is great.
--
OCLUG general discussion list
[email protected]
http://oclug.on.ca/mailman/listinfo/oclug