The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparing Two Strings Anji Shell Programming and Scripting 8 01-09-2008 06:32 AM
Grepping for strings t4st33@mac.com UNIX for Dummies Questions & Answers 5 06-20-2007 11:51 PM
copying strings... priya_9patil Shell Programming and Scripting 1 11-04-2006 12:26 PM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 11:58 AM
ksh - strings itzcoolbuddy Shell Programming and Scripting 1 06-22-2005 10:26 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-07-2008
rleal rleal is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
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 05:46 AM.. Reason: added code tags
  #2 (permalink)  
Old 07-07-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
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
An output example might make it much easier to understand, ty.
  #3 (permalink)  
Old 07-07-2008
rleal rleal is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
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 (permalink)  
Old 07-07-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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 07:52 AM..
  #5 (permalink)  
Old 01-01-2009
darius2 darius2 is offline
Banned
  
 

Join Date: Jan 2009
Posts: 26
Quote:
Originally Posted by radoulov View Post
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
  #6 (permalink)  
Old 01-02-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
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;
  #7 (permalink)  
Old 07-07-2008
rleal rleal is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
Yes, that one did it!! Thanks a lot,

r.-
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0