awk and NMEA strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and NMEA strings
# 1  
Old 07-07-2008
awk and NMEA strings

Hi all:

I have a file with NMEA sentences of the type:

Code:
$GPVTG,012.0,T,,M,00.0,N,,K*7D
$GPRMC,180541,A,3631.874,N,00617.423,W,00.0,004.0,210608,,*36
$SDDBT,,f,,M,,F*28
$GPGLL,3631.874,N,00617.423,W,180542,A*3B
$GPVTG,009.0,T,,M,00.0,N,,K*77
$GPVTG,019.0,T,,M,00.0,N,,K*76
$GPRMC,180546,A,3631.874,N,00617.423,W,00.0,019.0,210608,,*3D
$SDDBT,,f,,M,,F*28
$GPGLL,3631.874,N,00617.423,W,180548,A*31
$GPVTG,012.0,T,,M,00.0,N,,K*7D
$GPRMC,180551,A,3631.874,N,00617.423,W,00.0,004.0,210608,,*37
$GPVTG,004.0,T,,M,00.0,N,,K*7A
$SDDBT,,f,,M,,F*28
$GPGLL,3631.874,N,00617.423,W,180554,A*3C
$GPVTG,009.0,T,,M,00.0,N,,K*77
$GPRMC,180556,A,3631.874,N,00617.423,W,00.0,017.0,210608,,*32
$SDDBT,000016,f,00005,M,0002.7,F*01
$GPVTG,017.0,T,,M,00.0,N,,K*78
$GPGLL,3631.874,N,00617.423,W,180600,A*3E
$GPVTG,038.0,T,,M,00.0,N,,K*75
$GPRMC,180601,A,3631.874,N,00617.423,W,00.0,038.0,210608,,*3E
$SDDBT,000016,f,00005,M,0002.7,F*01

$GPRMC for position and time, $SDDBT for depth. All sentences are sequential in time.

I can extract position and time with awk, no problem:
Code:
gawk -F "," '$1=="$GPRMC" && $3 != "V" { print 20substr($10,5,2),substr($10,3,2),substr($10,1,2),substr($2,1,2),substr($2,3,2),substr($2,5,2),substr($6,1,3),substr($6,4),substr($4,1,2),substr($4,3)}' NMEAfile >output

and depth:
Code:
gawk -F "," '$1=="$SDDBT" && $4 !="" { print $4}' NMEAfile >output

I would like to combine position, time and depth into one single file, only if depth is true (note that sometimes $SDDBT,,f,,M,,F*28 -no depth info-). That is, if depth is true then use the position from the previous occurrence of $GPRMC and combine them into a single line. Sure that's possible with awk/gawk, but don't know how to do it.

Thanks in advance,

r.-

Last edited by radoulov; 07-07-2008 at 06:46 AM.. Reason: added code tags
# 2  
Old 07-07-2008
I am not sure if I got it right and what your wanted output should like, but to be sure you don't get the lines with "no depth info", why not just append that expression the the awk you already have like
Code:
... && !/no depth info/

You used such stuff in your awk line already so.. maybe I just did not understand Smilie
An output example might make it much easier to understand, ty.
# 3  
Old 07-07-2008
Sorry for the misunderstanding. I cannot add your suggestion because each sentence is written in a different line. The desired output from

Code:
 $GPRMC,180541,A,3631.874,N,00617.423,W,00.0,004.0,210608,,*36
$SDDBT,,f,,M,,F*28
$GPGLL,3631.874,N,00617.423,W,180542,A*3B
$GPVTG,009.0,T,,M,00.0,N,,K*77
$GPVTG,019.0,T,,M,00.0,N,,K*76
$GPRMC,180546,A,3631.874,N,00617.423,W,00.0,019.0,210608,,*3D
$SDDBT,,f,,M,,F*28
$GPGLL,3631.874,N,00617.423,W,180548,A*31
$GPVTG,012.0,T,,M,00.0,N,,K*7D
$GPRMC,180551,A,3631.874,N,00617.423,W,00.0,004.0,210608,,*37
$GPVTG,004.0,T,,M,00.0,N,,K*7A
$SDDBT,,f,,M,,F*28
$GPGLL,3631.874,N,00617.423,W,180554,A*3C
$GPVTG,009.0,T,,M,00.0,N,,K*77
$GPRMC,180556,A,3631.874,N,00617.423,W,00.0,017.0,210608,,*32
$SDDBT,000016,f,00005,M,0002.7,F*01
$GPVTG,017.0,T,,M,00.0,N,,K*78

would be

Code:
 
210608 180556 36 31.874 00617.423 00005

What it should do is get the depth (if not empty) and grab the corresponding lat,lon,time from the immediately previous $GPRMC line. In this example the first 3 $SDDBT sentences have no depth info (with comma as separators ,, means empty value).

best regs,

r.-
# 4  
Old 07-07-2008
Code:
awk -F,>ouput '/GPRMC/ {
  _ = $(NF-2) s $2 s substr($4, 1, 2) s substr($4, 3) s $6 
}
/SDDBT/ && $2 { print _, $4 }
' s=" " NMEAfile

And if SDDBT always follows immediately GPRMC,
this should be sufficient:

Code:
awk -F,>ouput '/SDDBT/ && $2 { print _, $4 }
{ _ = $(NF-2) s $2 s substr($4, 1, 2) s substr($4, 3) s $6 }
' s=" " NMEAfile


Last edited by radoulov; 07-07-2008 at 08:52 AM..
# 5  
Old 07-07-2008
Yes, that one did it!! Thanks a lot,

r.-
# 6  
Old 01-01-2009
Quote:
Originally Posted by radoulov
Code:
awk -F,>ouput '/GPRMC/ {
  _ = $(NF-2) s $2 s substr($4, 1, 2) s substr($4, 3) s $6 
}
/SDDBT/ && $2 { print _, $4 }
' s=" " NMEAfile

And if SDDBT always follows immediately GPRMC,
this should be sufficient:

Code:
awk -F,>ouput '/SDDBT/ && $2 { print _, $4 }
{ _ = $(NF-2) s $2 s substr($4, 1, 2) s substr($4, 3) s $6 }
' s=" " NMEAfile

Hi,

I have the same problem with NMEA sentences, streamed on-line to stadout, in terminal session, running gpsd or gpspipe.
I would like to learn how to pipe NMEA into awk script code
to get selected gps data like long, lat, speed, time
from selected NMEA sentences, for use in another pipelined application.

First I need to create NMEA > AWK > output pipe

Got a nice example from
Info: (gawk.info) Getline/Pipe
awk '{
if ($1 == "@execute") {
tmp = substr($0, 10)
while ((tmp | getline) > 0)
print
close(tmp)
} else
print
}'
and another awk manual with examples
The GAWK Manual - Reading Input Files

Got another example

I am trying to create a pipeline which prints every word on a new line, then sorts them and applies uniq -c to it!
{c=split($0, s); for(n=1; n<=c; ++n) print s[n] | "sort" | "uinq -c"}


answer


fmt -1 filename|sed 's/[ ,.":;!]//g'|sort -f|uniq -ci

What is a way to create a pipeline for a data stream generated by gpsd, gpspipe ?

gpsd > filename |sed ..
gpsd | getline .....

Or just please refer me to a nice place.

Thanks.
Happy New Year

Darius
# 7  
Old 01-02-2009
Hi not very sure about your detail logic, but below perl script may help you some

Code:
#! /usr/bin/perl
open FH,"<a.txt";
while(<FH>){
	my @tmp=split(",",$_);
	if($tmp[0] eq "\$GPRMC"){
		$tmp=$tmp[9]."-".$tmp[1];
	}
	if($tmp[0] eq "\$SDDBT"){
		my @arr=split(",",$_);
		print $tmp.":".$arr[3]."\n" if($arr[3] ne "");
	}
}
close FH;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

(g)awk: Matching strings from one file in another file between two strings

Hello all, I can get close to what I am looking for but cannot seem to hit it exactly and was wondering if I could get your help. I have the following sample from textfile with many thousands of lines: File 1 PS001,001 HLK PS002,004 L<G PS004,002 XNN PS004,006 BVX PS004,006 ZBX=... (7 Replies)
Discussion started by: jvoot
7 Replies

2. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

3. Shell Programming and Scripting

Using awk to replace strings

Hi.. I have a file that has the following content : abc 213 24 213 pqr 456#34 678 xyz 213 45%213 i need to write an awk script that will replace the second 213 in all the lines, if it is present. The IFS can not be specified and can be random. The number of lines in the file and the... (5 Replies)
Discussion started by: Hermione Grange
5 Replies

4. Shell Programming and Scripting

awk Splitting strings

Hi All, There is a file with a data. If the line is longer than 'n', we splitting the line on the parts and print them. Each of the parts is less than or equal 'n'. For example: n = 2; "ABCDEFGHIJK" -> length 11 Results: "AB" "CD" EF" GH" "IJ" "K" Code, but there are some errors.... (9 Replies)
Discussion started by: booyaka
9 Replies

5. Shell Programming and Scripting

awk to get text between 2 strings

Hi, I am trying different scenarios now, 1 of those is getting the text between the following 2 strings. Type of msg: -in_full >date >alr text >ID_on_exit AWXX-Ready to commit (98) msg type: (10) I need to get all the occurrences having the same start line and end line.... (6 Replies)
Discussion started by: ocramas
6 Replies

6. Shell Programming and Scripting

Grabbing strings with awk

Hello everyone, I am doing some sort of analysis for some data about organic solvents, and I have a problem with writing a command to do this: Here's a sample of my file: 1 ethanol 2 methanol 3 methanol/ethanol 4 ethanol/methanol 5 ethanol/DMF 6 ethyl... (6 Replies)
Discussion started by: Error404
6 Replies

7. Shell Programming and Scripting

Using Awk to Search Two Strings on One Line

If i wanted to search for two strings that are on lines in the log, how do I do it? The following code searches for just one string that is one one line. awk '/^/ {split($2,s,",");a=$1 FS s} /failure agaf@fafa/ {b=a} END{print b}' urfile What if I wanted to search for "failure agaf@fafa"... (3 Replies)
Discussion started by: SkySmart
3 Replies

8. Shell Programming and Scripting

gpsd, gpspipe NMEA sentences stream processing

Hi, running gpsd, gpspipe I get a stream of NMEA sentences. What I need is to write awk script for pipelining and on-the-fly processing of the streamed NMEA senteces to output (terminal session in my case). The issue is, I can get gpsd working in -D 5 mode (debug mode). There is no issue... (5 Replies)
Discussion started by: darius2
5 Replies

9. Shell Programming and Scripting

How to print only lines in between two strings using awk

Hi, I want to print only lines in between two strings and not the strings using awk. Eg: OUTPUT top 2 bottom 1 left 0 right 0 page 66 END I want to print into a new file only top 2 bottom 1 left 0... (4 Replies)
Discussion started by: jisha
4 Replies
Login or Register to Ask a Question