nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

shell script to read a line in gps receiver log file and append that line to new file

This is a discussion on shell script to read a line in gps receiver log file and append that line to new file within the Shell scripting forums, part of the Development/Scripting category; Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 23-06-2009, 10:04 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gudivada213 is on a distinguished road
Default shell script to read a line in gps receiver log file and append that line to new file

Hi,

I have gps receiver log..its giving readings .like below

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GPSD,R=1
$GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283, 39,20,11,165,00*71
$GPGSV,3,2,11,17,24,208,39,27,11,097,00,13,87,174, 00,19,31,042,00*70
$GPGSV,3,3,11,25,43,033,38,03,07,037,00,23,47,150, 00*44
$GPGGA,111503,0833.6323,N,07652.7685,E,1,04,1.60,1 6.69,M,-94.088,M,,*58
$GPRMC,111503,A,0833.6323,N,07652.7685,E,0.1866,25 6.540,220609,,*2A
$GPGSA,A,3,08,28,17,25,,,,,,,,,0.0,1.6,16.3*02
$GPGGA,111504,0833.6316,N,07652.7682,E,1,04,1.60,1 8.70,M,-94.088,M,,*58
$GPRMC,111504,A,0833.6316,N,07652.7682,E,0.1866,25 6.540,220609,,*2C
$GPGSA,A,3,08,28,17,25,,,,,,,,,0.0,1.6,16.3*02
$PGRME,0.00,M,0.00,M,0.00,M*1E
$GPGGA,111505,0833.6328,N,07652.7684,E,1,04,1.60,2 5.15,M,-94.088,M,,*5F
$GPRMC,111505,A,0833.6328,N,07652.7684,E,0.1488,23 8.090,220609,,*2A
$GPGSA,A,3,08,28,17,25,,,,,,,,,0.0,1.6,16.3*02
$GPGGA,111506,0833.6336,N,07652.7654,E,1,04,1.60,2 7.75,M,-94.088,M,,*5A
$GPRMC,111506,A,0833.6336,N,07652.7654,E,0.1866,25 6.540,220609,,*27
$GPGSA,A,3,08,28,17,25,,,,,,,,,0.0,1.6,16.3*02
$PGRME,0.00,M,0.00,M,0.00,M*1E
$GPGGA,111507,0833.6341,N,07652.7644,E,1,04,1.60,2 9.31,M,-94.088,M,,*54
$GPRMC,111507,A,0833.6341,N,07652.7644,E,0.1866,25 6.540,220609,,*27
$GPGSA,A,3,08,28,17,25,,,,,,,,,0.0,1.6,16.3*02
-
-
--
--
what i need?
Shell script has to check for each log line starting word with "$GPRMC", if line starts with $GPRMC, then that line has to append a new file data.txt

For example:

when i started the gps receiver log is giving
first line: Trying 127.0.0.1... has to check whether it is started with $GPRMC
then when the second line came log again has to check..like...up to terminating the log.
this process has to start when the log started...

if the line starts with $GPRMC the line has to append new line...


thanks in advance,

sravan
Reply With Quote
  #2 (permalink)  
Old 24-06-2009, 11:25 PM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Scripting language: BASH - Learning Ruby
Posts: 602
Thanks: 61
Thanked 80 Times in 72 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default Hello Sir

Please give this a try.

Code:
cat gps_log_file | grep GPRMC > data.txt
This will generate the following from your test data:
Code:
shine:bin jasonralph$ cat data1 | grep GPRMC 
$GPRMC,111503,A,0833.6323,N,07652.7685,E,0.1866,25 6.540,220609,,*2A
$GPRMC,111504,A,0833.6316,N,07652.7682,E,0.1866,25 6.540,220609,,*2C
$GPRMC,111505,A,0833.6328,N,07652.7684,E,0.1488,23 8.090,220609,,*2A
$GPRMC,111506,A,0833.6336,N,07652.7654,E,0.1866,25 6.540,220609,,*27
$GPRMC,111507,A,0833.6341,N,07652.7644,E,0.1866,25 6.540,220609,,*27
I created a file called data1 with your test data for the input file. Of course swap data1 file out for your log file.



Good Luck

Jaysunn
Reply With Quote
  #3 (permalink)  
Old 28-06-2009, 09:10 PM
amitabh's Avatar
Contributors
User
 
Join Date: Jul 2008
Location: New Delhi
OS: FreeBSD
Posts: 99
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Power: 4
amitabh has a spectacular aura about amitabh has a spectacular aura about amitabh has a spectacular aura about
Send a message via MSN to amitabh Send a message via Yahoo to amitabh Send a message via Skype™ to amitabh
Default

Code:
cat gps_log_file | grep GPRMC >> data.txt
If you need to append to the same file use the double redirection.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to read configuration file line by line in C ? demuytree Coding in General 1 26-06-2009 09:00 PM
Script to open and read a file that is supplied as a command line arg blingbling Shell scripting 3 31-03-2009 10:54 AM
Shell script tp Log files last line kasimani Shell scripting 3 24-03-2009 03:25 PM
Shell script to count number of lines in file specified by the second command-line seaman77 Shell scripting 1 16-03-2009 07:46 PM
Omit the first line in a file c341 Shell scripting 4 29-12-2006 02:07 PM


All times are GMT +5.5. The time now is 04:35 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38