![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 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
Code:
gawk -F "," '$1=="$SDDBT" && $4 !="" { print $4}' NMEAfile >output
Thanks in advance, r.- Last edited by radoulov; 07-07-2008 at 05:46 AM.. Reason: added code tags |
|
||||
|
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 Code:
210608 180556 36 31.874 00617.423 00005 best regs, r.- |
|
|||||
|
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
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.. |
|
||||
|
Quote:
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) close(tmp) } else }' 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 |
|
||||
|
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;
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|