- Member Success Stories (
-   -   Tools to parse NMEA GPS data : grep & awk (

mjolnir 07-19-2010 08:20 AM

Tools to parse NMEA GPS data : grep & awk
Recently I decided to fire up an old gps unit (Earthmate GPS BT-20) I had laying around and see if I could get it to run with Ubuntu 10.04.

Plug in the unit and give it time to acquire a fix then check dmesg to see what device name it has been given. If desired you can assign the device a permanent location with udev. In my case the unit was located at /dev/ttyUSB4.

carl@wizard:~$ cat /dev/ttyUSB4

These are NMEA sentences. To save to a file open a terminal and run

cat /dev/ttyUSB4> file.txt
Use control-C to stop the process.


cat /dev/ttyUSB4 | grep --line-buffered  GPGGA > earth.txt
will write selected lines, in this case GPGGA to a file.


awk -F, '/\$GPGGA/ {print  strftime("%Y-%m-%d "),  $2, (substr($3,0,2) + (substr($3,3) / 60.0)) $4,  (substr($5,0,3) + (substr($5,4) / 60.0)) $6, $10; fflush();}' /dev/ttyUSB4 > earth1.txt
This command will cut out the info I want: time,lat/long, altitude and add the date.

I got part of the awk string here:

and the rest of it here:

especially the part about line buffered input.

All times are GMT -5. The time now is 08:39 AM.