Sponsored Content
Top Forums Shell Programming and Scripting shell script to read a line in gps receiver log file and append that line to new file Post 302328161 by durden_tyler on Tuesday 23rd of June 2009 02:37:16 PM
Old 06-23-2009
Quote:
Originally Posted by gudivada213
...
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
...
Seems like the "grep" command could help you here.
Check the syntax by executing the command "man grep" on your Unix/Linux prompt.

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shell script to read file line by line

Hi, I need to read a text file from shell script line by line and copy the feilds of each line. Below is the complete requirement. I've text file which contains ... pgm1 file11 file12 file13 pgm2 file21 file22 pgm3 file31 file32 file33 I'll give input as... (4 Replies)
Discussion started by: ani12345
4 Replies

2. Shell Programming and Scripting

How to append value at first line of CSV file using shell script?

I have an issue where I need to append a value at the last of the csv, I have created a shell script and it is appending the columns at the last but it is appending at all lines, and my requirement is specific to just append at the 1st line. Have a look and suggest, (7 Replies)
Discussion started by: anujrichhariya
7 Replies

3. Shell Programming and Scripting

how can u read a file line by line in shell script ?

hello , plz help for below script req:- how can we read a file line by line in shell script ? (4 Replies)
Discussion started by: abhigrkist
4 Replies

4. Shell Programming and Scripting

help needed with shell script to append to the end of a specific line in a file on multiple servers

Hi Folks, I was given a task to append three IP's at the end of a specific (and unique) line within a file on multiple servers. I was not able to do that with the help of a script. All I could was: for i in server1 server2 server3 server4 do ssh $i done I know 'sed' could be used to... (5 Replies)
Discussion started by: momin
5 Replies

5. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

6. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

7. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

8. Shell Programming and Scripting

Read line from the file and append it to each row

Hi All, We have a file in the following format: 0.010000 $ ITI 11 LV2 $ 40456211 $ 0.135000 $ ITI 11 LV1 $ 40512211 $ 1.215600 $ ITI 11 ITI3 $ 41406211 $ 24/05/2014 14:05:02 0.030000 $ ITI 11 LV2 $ 40456211 $ ... (3 Replies)
Discussion started by: gauravsinghal79
3 Replies

9. Shell Programming and Scripting

Needed shell script to append desired text to each line in a file

Hi, I had generated a report in my tool as followsoutput.txt 43.35 9 i needed the script to generate a new file like below i want to append the text to each of these lines of my filenewoutputfile.txt should be Total Amount : 43.35 Record Count:9 Regards, Vasa Saikumar. ... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

10. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies
3(3)								GPSD Documentation							      3(3)

NAME
libgps - C service library for communicating with the GPS daemon SYNOPSIS
C: #include <gps.h> int gps_open(char *server, char * port, struct gps_data_t *gpsdata); int gps_send(struct gps_data_t *gpsdata, char *fmt...); int gps_read(struct gps_data_t *gpsdata); bool gps_waiting(const struct gps_data_t *gpsdata, int timeout); char *gps_data(const struct gps_data_t *gpsdata); int gps_unpack(char *buf, struct gps_data_t *gpsdata); void gps_close(struct gps_data_t *gpsdata); int gps_stream(struct gps_data_t *gpsdata, unsigned intflags, void *data); const char *gps_errstr(int err); Python: import gps session = gps.gps(host="localhost", port="2947") session.stream(flags=gps.WATCH_JSON) for report in session: process(report) del session DESCRIPTION
libgps is a service library which supports communicating with an instance of the gpsd(8); link it with the linker option -lgps. Warning Take care to conditionalize your code on the major and minor API version symbols in gps.h; ideally, force a compilation failure if GPSD_API_MAJOR_VERSION is not a version you recognize. See the GPSD project website for more information on the protocol and API changes. Calling gps_open() initializes a GPS-data structure to hold the data collected by the GPS, and sets up access to gpsd(1) via either the socket or shared-memory export. The shared-memory export is faster, but does not carry information about device activation and deactivation events and will not allow you to monitor device packet traffic. gps_open() returns 0 on success, -1 on errors and is re-entrant. errno is set depending on the error returned from the socket or shared-memory interface; see gps.h for values and explanations; also see gps_errstr(). The host address may be a DNS name, an IPv4 dotted quad, an IPV6 address, or the special value GPSD_SHARED_MEMORY referring to the shared-memory export; the library will do the right thing for any of these. gps_close() ends the session. gps_send() writes a command to the daemon. It does nothing when using the shared-memory export. The second argument must be a format string containing elements from the command set documented at gpsd(1). It may have % elements as for sprintf(3), which will be filled in from any following arguments. This function returns a -1 if there was a Unix-level write error, otherwise 0. Please read the LIMITATIONS section for additional information and cautions. See gps_stream() as a possible alternative. gps_read() accepts a response, or sequence of responses, from the daemon and interprets. This function does either a nonblocking read for data from the daemon or a fetch from shared memory; it returns a count of bytes read for success, -1 with errno set on a Unix-level read error, -1 with errno not set if the socket to the daemon has closed or if the shared-memory segment was unavailable, and 0 if no data is available. gps_waiting() can be used to check whether there is new data from the daemon. The second argument is the maximum amount of time to wait (in microseconds) on input before returning. It returns true if there is input waiting, false on timeout (no data waiting) or error condition. This function is a convenience wrapper around a select(2) call, and zeros errno on entry; you can test errno after exit to get more information about error conditions. gps_unpack() parses JSON from the argument buffer into the target of the session structure pointer argument. Included in case your application wishes to manage socket I/O itself. gps_data() returns the contents of the client data buffer (it returns NULL when using the shared-memory export). Use with care; this may fail to be a NUL-terminated string if WATCH_RAW is enabled. gps_stream() asks gpsd to stream the reports it has at you, to be made available when you poll (not available when using the shared-memory export). The second argument is a flag mask that sets various policy bits; see the list below. Calling gps_stream() more than once with different flag masks is allowed. WATCH_DISABLE Disable the reporting modes specified by the other WATCH_ flags. WATCH_ENABLE Disable the reporting modes specified by the other WATCH_ flags. This is the default. WATCH_JSON Enable JSON reporting of data. If WATCH_ENABLE is set, and no other WATCH flags are set, this is the default. WATCH_NMEA Enable generated pseudo-NMEA reporting on binary devices. WATCH_RARE Enable reporting of binary packets in encoded hex. WATCH_RAW Enable literal passthrough of binary packets. WATCH_SCALED When reporting AIS or Subframe data, scale integer quantities to floats if they have a divisor or rendering formula associated with them. WATCH_NEWSTYLE Force issuing a JSON initialization and getting new-style responses. This is the default. WATCH_OLDSTYLE Force issuing a W or R command and getting old-style responses. Warning: this flag (and the capability) will be removed in a future release. WATCH_DEVICE Restrict watching to a specified device, patch given as second argument. gps_errstr() returns an ASCII string (in English) describing the error indicated by a nonzero return value from gps_open(). Consult gps.h to learn more about the data members and associated timestamps. Note that information will accumulate in the session structure over time, and the 'valid' field is not automatically zeroed by each gps_read(). It is up to the client to zero that field when appropriate and to keep an eye on the fix and sentence timestamps. The Python implementation supports the same facilities as the socket-export calls in the C library; there is no shared-memory interface. gps_open() is replaced by the initialization of a gps session object; the other calls are methods of that object, and have the same names as the corresponding C functions. However, it is simpler just to use the session object as an iterator, as in the example given below. Resources within the session object will be properly released when it is garbage-collected. CODE EXAMPLE
The following is an excerpted and simplified version of the libgps interface code from cgps(1). struct gps_data_t gps_data; ret = gps_open(hostName, hostPort, &gps_data); (void) gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL); /* Put this in a loop with a call to a high resolution sleep () in it. */ if (gps_waiting (&gps_data, 500)) { errno = 0; if (gps_read (&gps_data) == -1) { ... } else { /* Display data from the GPS receiver. */ if (gps_data.set & ... } } /* When you are done... */ (void) gps_stream(&gps_data, WATCH_DISABLE, NULL); (void) gps_close (&gps_data); LIMITATIONS
On some systems (those which do not support implicit linking in libraries) you may need to add -lm to your link line when you link libgps. It is always safe to do this. In the C API, incautious use of gps_send() may lead to subtle bugs. In order to not bloat struct gps_data_t with space used by responses that are not expected to be shipped in close sequence with each other, the storage for fields associated with certain responses are combined in a union. The risky set of responses includes VERSION, DEVICELIST, RTCM2, RTCM3, SUBFRAME, AIS, GST, and ERROR; it may not be limited to that set. The logic of the daemon's watcher mode is careful to avoid dangerous sequences, but you should read and understand the layout of struct gps_data_t before using gps_send() to request any of these responses. COMPATIBILITY
The gps_query() supported in major versions 1 and 2 of this library has been removed. With the new streaming-oriented wire protocol behind this library, it is extremely unwise to assume that the first transmission from the daemon after a command is shipped to it will be the response to command. If you must send commands to the daemon explicitly, use gps_send() but beware that this ties your code to the GPSD wire protocol. It is not recommended. In earlier versions of the API gps_read() was a blocking call and there was a POLL_NONBLOCK option to make it nonblocking. gps_waiting() was added to reduce the number of wrong ways to code a polling loop. See the comment above the symbol GPSD_API_MAJOR_VERSION in gps.h for recent changes. SEE ALSO
gpsd(8), gps(1), libgpsd(3). libgpsmm(3). AUTHOR
Eric S. Raymond <esr@thyrsus.com>, C sample code Charles Curley <charlescurley@charlescurley.com> The GPSD Project 14 Aug 2004 3(3)
All times are GMT -4. The time now is 09:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy