LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 07-19-2010, 07:20 AM   #1
mjolnir
Member
 
Registered: Apr 2003
Posts: 824

Rep: Reputation: 106Reputation: 106
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.
Code:
carl@wizard:~$ cat /dev/ttyUSB4
$GPGGA,115931.000,xxxx.xxxxx,N,xxxxx.xxxxx,W,1,09,1.2,173.59,M,-31.9,M,,*53
$GPGSV,3,1,12,01,65,295,00,09,25,043,39,12,16,095,31,14,60,290,40*71
$GPGSV,3,2,12,18,48,101,34,19,08,281,00,21,19,168,31,22,76,034,35*74
$GPGSV,3,3,12,24,61,244,38,27,14,039,31,30,14,131,38,31,20,202,00*74
$GPGSA,A,3,14,22,24,18,09,21,27,12,30,,,,2.1,1.2,1.7*31
$GPRMC,115932.000,A,xxxx.xxx,N,xxxxx.xxx,W,0.0,0.0,190710,0.0,E*77
$GPGGA,115932.000,xxxx.xxxxx,N,xxxxx.xxxxx,W,1,09,1.2,173.59,M,-31.9,M,,*5A
$GPGSV,3,1,12,01,65,295,00,09,25,043,40,12,16,095,30,14,60,290,40*7E
$GPGSV,3,2,12,18,48,101,35,19,08,281,00,21,19,168,30,22,76,034,35*74
$GPGSV,3,3,12,24,61,244,38,27,14,039,31,30,14,131,38,31,20,202,00*74
$PSTMECH,14,7,22,7,00,0,24,7,18,7,09,7,21,7,00,0,27,7,00,0,12,7,30,7*56
These are NMEA sentences. To save to a file open a terminal and run
Code:
cat /dev/ttyUSB4> file.txt
Use control-C to stop the process.

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

Code:
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: http://wiki.openmoko.org/wiki/Gettin...put_with_gllin

and the rest of it here: http://stackoverflow.com/questions/2...-lines-of-text

especially the part about line buffered input.

Last edited by mjolnir; 07-19-2010 at 09:05 AM. Reason: Prematurely hit the save button.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get data from multi lined text file using awk, sed or perl - grep & cut not upto par cam34 Programming 4 07-02-2010 03:10 AM
Python script parse NMEA data from GlobalSat BU-353 buffdigger Linux - Newbie 1 04-07-2010 07:29 PM
Reading NMEA from GPS and output it in the USB port OlaJi Linux - Hardware 1 05-21-2009 06:56 AM
sed/awk/grep for multiple line data hotrodmacman Programming 8 10-18-2007 11:06 AM
How do I zip and attach the output data of a grep | awk | mail shell script? 360 Programming 1 05-08-2002 08:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 09:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration