Sponsored Content
Top Forums Shell Programming and Scripting Extract header data from one file and combine it with data from another file Post 302758453 by nex_asp on Saturday 19th of January 2013 01:21:13 PM
Old 01-19-2013
Sir as I got one small problem in appending header please help.

I modified as per my requirement
Code:
#!/bin/ksh
# Usage: runner hdr main [hdr main]...
if [ $# -lt 2 ] || [ $(($# % 2)) -ne 0 ]
then    printf "%s: Odd number of operands or less than two operands:\n" $0 >&2
        printf "Usage: %s hdr main [hdr main]...\n" "$0" >&2
        exit 1
fi
while [ $# -ge 2 ]
do      hf="$1"
        mf="$2"
        shift 2
        awk    'BEGIN{
                m["Jan"] = 1; m["Feb"] = 2;  m["Mar"] = 3;  m["Apr"] = 4
                m["May"] = 5; m["Jun"] = 6;  m["Jul"] = 7;  m["Aug"] = 8
                m["Sep"] = 9; m["Oct"] = 10; m["Nov"] = 11; m["Dec"] = 12
                FS = "[:=] "
  printf("Date\tTime\tLatitude\t%s","Longitude\tPrDM\tT090C\tC0S/m\tDepSM\tSal00\tDensity00\tSigma-é00\tOxsolML/L\tSvCM\n")
        }

    FNR>1 && FNR!=NR{printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", hdr, $1, $2, $3, $4, $5, $6, $7, $8, $9);next}
               
        FNR==NR && /System UpLoad/{split($2, a, "  *");dt=sprintf("%02d/%02d/%02d", a[2], m[a[1]], a[3] % 100);tm=a[4];next}

    FNR==NR && /NMEA Latitude/{lat = $2;next}

        FNR==NR && /NMEA Longitude/{lon = $2;next}

        FNR==1  && NR>1{FS = "\t\t";hdr = sprintf("%s\t%s\t%s\t%s",dt, tm, lat, lon)
    next
        }' "$hf" "$mf"
done

I attached data and header file also but latitude and longitude not coming, if I make
Code:
 FNR==NR && /NMEA Longitude/{lon = $2;next}

to
Code:
FNR==NR && /^NMEA Longitude/{lon = $2;next}

I can see time otherwise not

please tell me where I am doing wrong also
 

10 More Discussions You Might Find Interesting

1. Programming

to find header in Mp3 file and retrieve data

hi all, In an mp3 file , data is arranged in sequence of header and data ,how to retrieve data between two headers. Is the data between two headers fixed? because as per theory it says 1152 samples will be there , but dont knw how many bits one sample correspond to? it would help if any c... (2 Replies)
Discussion started by: shashi
2 Replies

2. Shell Programming and Scripting

insert a header in a huge data file without using an intermediate file

I have a file with data extracted, and need to insert a header with a constant string, say: H|PayerDataExtract if i use sed, i have to redirect the output to a seperate file like sed ' sed commands' ExtractDataFile.dat > ExtractDataFileWithHeader.dat the same is true for awk and... (10 Replies)
Discussion started by: deepaktanna
10 Replies

3. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

4. Shell Programming and Scripting

Extract specific content from data and rename its header problem asking

Input file 1: >pattern_5 GAATTCGTTCATGTAGGTTGASDASFGDSGRTYRYGHDGSDFGSDGGDSGSDGSDFGSDF ATTTAATTATGATTCATACGTCATATGTTATTATTCAATCGTATAAAATTATGTGACCTT SDFSDGSDFKSDAFLKJASLFJASKLFSJAKJFHASJKFHASJKFHASJKFHSJAKFHAW >pattern_1 AAGTCTTAAGATATCACCGTCGATTAGGTTTATACAGCTTTTGTGTTATTTAAATTTGAC... (10 Replies)
Discussion started by: patrick87
10 Replies

5. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

6. Shell Programming and Scripting

get data from files combine them to a file

hi people; this is my file1.txt:192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 ... this is my file2.txt:portnames usernames maxusercap ... i want to write to file3.txt:l ./getports 192.168.1.1 'get all;l+;get . portnames;l-' l ./getports 192.168.1.1 'get all;l+;get . usernames;l-'... (4 Replies)
Discussion started by: gc_sw
4 Replies

7. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

8. Shell Programming and Scripting

How to combine data from 2 file ? How to print ?

Dear friends, I am just trying to print data from 2 file,namely file_1.txt and file_1.dat (specific column of ROW 1) file_1.txt 12 13 14 15 99 AMC 69 36 89 12 13 14 15 99 AMC 69 84 -12 12 13 14 ... (6 Replies)
Discussion started by: nex_asp
6 Replies

9. Shell Programming and Scripting

Combine data out of 3 files into one new file

Hi, How can I combine the data of of three files into one new file? I try to give as much informations as possible. The three existing files are called file1 file2 and file3 the new file should named output_combined. The size of the files will be around 900 words/lines each .. but always... (5 Replies)
Discussion started by: MyMemberName
5 Replies

10. Shell Programming and Scripting

Bash to verify and validate file header and data type

The below bash is a file validation check executed that will verify the correct header count of 10 and the correct data type in each field of the tab-delimited file. The key has the data type of each field in it. My real data has 58 headers in it but only the header and next row need to be... (6 Replies)
Discussion started by: cmccabe
6 Replies
GPS::Point(3pm) 					User Contributed Perl Documentation					   GPS::Point(3pm)

NAME
GPS::Point - Provides an object interface for a GPS point. SYNOPSIS
use GPS::Point; my $obj=GPS::Point->newGPSD($GPSD_O_line);#e.g. GPSD,O=.... my $obj=GPS::Point->new( time => $time, #float seconds from the unix epoch lat => $lat, #signed degrees lon => $lon, #signed degrees alt => $hae, #meters above the WGS-84 ellipsoid speed => $speed, #meters/second (over ground) heading => $heading, #degrees clockwise from North climb => $climb, #meters/second etime => $etime, #float seconds ehorizontal => $ehz, #float meters evertical => $evert, #float meters espeed => $espeed, #meters/second eheading => $ehead, #degrees eclimb => $eclimb, #meters/second mode => $mode, #GPS mode [?=>undef,None=>1,2D=>2,3D=>3] tag => $tag, #Name of the GPS message for data ); DESCRIPTION
This is a re-write of Net::GPSD::Point with a goal of being more re-usable. GPS::Point - Provides an object interface for a GPS fix (e.g. Position, Velocity and Time). Note: Please use Geo::Point, if you want 2D or projection support. USAGE
print scalar($point->latlon), " "; #latlon in scalar context my ($x,$y,$z)=$point->ecef; #if Geo::ECEF is available my $GeoPointObject=$point->GeoPoint; #if Geo::Point is available my @distance=$point->distance($point2); #if Geo::Inverse is available my $distance=$point->distance($point2); #if Geo::Inverse->VERSION >=0.05 USAGE TODO
my $obj=GPS::Point->newNMEA($NMEA_lines); #e.g. GGA+GSA+RMC CONSTRUCTOR
new my $obj = GPS::Point->new(); newGPSD my $obj=GPS::Point->newGPSD($GPSD_O_line);#e.g. GPSD,O=.... newMulti Constructs a GPS::Point from a Multitude of arguments. Arguments can be a GPS::Point, Geo::Point, {lat=>$lat,lon=>$lon} (can be blessed), [$lat, $lon] (can be blessed) or a ($lat, $lon) pair. my $point=GPS::Point->newMulti( $lat, $lon, $alt ); #supports lat, lon and alt my $point=GPS::Point->newMulti([$lat, $lon, $alt]); #supports lat, lon and alt my $point=GPS::Point->newMulti({lat=>$lat, lon=>$lon, ...}); my $point=GPS::Point->newMulti(GPS::Point->new(lat=>$lat, lon=>$lon)); my $point=GPS::Point->newMulti(Geo::Point->new(lat=>$lat, long=>$lon, proj=>'wgs84')); my $point=GPS::Point->newMulti({latitude=>$lat, longtude=>$lon}); Note: Hash reference context supports the following keys lat, lon, alt, latitude, longitude, long, altitude, elevation, hae, elev. Note: Units are always decimal degrees for latitude and longitude and meters above the WGS-84 ellipsoid for altitude. initialize, initializeGPSD, initializeMulti METHODS (Base) time Sets or returns seconds since the Unix epoch, UTC (float, seconds) print $obj->time, " "; lat, latitude Sets or returns Latitude (float, degrees) print $obj->lat, " "; lon, long or longitude Sets or returns Longitude (float, degrees) print $obj->lon, " "; alt, altitude, hae, elevation Sets or returns Altitude (float, meters) print $obj->alt, " "; speed Sets or returns speed (float, meters/sec) print $obj->speed, " "; heading, bearing Sets or returns heading (float, degrees) print $obj->heading, " "; climb Sets or returns vertical velocity (float, meters/sec) print $obj->climb, " "; etime Sets or returns estimated timestamp error (float, seconds, 95% confidence) print $obj->etime, " "; ehorizontal Sets or returns horizontal error estimate (float, meters) print $obj->ehorizontal, " "; evertical Sets or returns vertical error estimate (float, meters) print $obj->evertical, " "; espeed Sets or returns error estimate for speed (float, meters/sec, 95% confidence) print $obj->espeed, " "; eheading Sets or returns error estimate for course (float, degrees, 95% confidence) print $obj->eheading, " "; eclimb Sets or returns Estimated error for climb/sink (float, meters/sec, 95% confidence) print $obj->eclimb, " "; mode Sets or returns the NMEA mode (integer; undef=>no mode value yet seen, 1=>no fix, 2=>2D, 3=>3D) print $obj->mode, " "; tag Sets or returns a tag identifying the last sentence received. For NMEA devices this is just the NMEA sentence name; the talker-ID portion may be useful for distinguishing among results produced by different NMEA talkers in the same wire. (string) print $obj->tag, " "; METHODS (Value Added) fix Returns either 1 or 0 based upon if the GPS point is from a valid fix or not. print $obj->fix, " "; At a minimum this method requires mode to be set. datetime Returns a DateTime object from time my $dt=$point->datetime; At a minimum this method requires time to be set. latlon, latlong Returns Latitude, Longitude as an array in array context and as a space joined string in scalar context my @latlon=$point->latlon; my $latlon=$point->latlon; At a minimum this method requires lat and lon to be set. setAltitude Sets altitude from USGS web service and then returns the GPS::Point object. This method is a wrapper around Geo::WebService::Elevation::USGS. my $point=GPS::Point->new(lat=>$lat, lon=>$lon)->setAltitude; $point->setAltitude; my $alt=$point->alt; At a minimum this method requires lat and lon to be set and alt to be undef. ecef Returns ECEF coordinates. This method is a warpper around Geo::ECEF. my ($x,$y,$z) = $point->ecef; my @xyz = $point->ecef; my $xyz_aref = $point->ecef; #if Geo::ECEF->VERSION >= 0.08 At a minimum this method requires lat and lon to be set. (alt of 0 is assumed by Geo::ECEF->ecef). GeoPoint Returns a Geo::Point Object in the WGS-84 projection. my $GeoPointObject = $point->GeoPoint; At a minimum this method requires lat and lon to be set. distance Returns distance in meters between the object point and the argument point. The argument can be any valid argument of newMulti constructor. This method is a wrapper around Geo::Inverse. my ($faz, $baz, $dist) = $point->distance($pt2); #Array context my $dist = $point->distance($lat, $lon); #if Geo::Inverse->VERSION >=0.05 At a minimum this method requires lat and lon to be set. track Returns a point object at the predicted location in time seconds assuming constant velocity. Using Geo::Forward calculation. my $new_point=$point->track($seconds); #default $point->heading my $new_point=$point->track($seconds => $heading); At a minimum this method requires lat and lon to be set. It might be very useful to have speed, heading and time set although they all default to zero. forward Returns a point object at the distance and heading using Geo::Forward calculations. my $point=$point->forward($dist); #default $point->heading my $point=$point->forward($dist => $heading); #meters => degrees At a minimum this method requires lat and lon to be set. It might be useful to have heading set although the default is zero. BUGS
Send to GPSD-DEV or GEO-PERL email lists SUPPORT
Try GPSD-DEV or GEO-PERL email lists AUTHOR
Michael R. Davis CPAN ID: MRDVT DavisNetworks.com account=>perl,tld=>com,domain=>michaelrdavis http://www.davisnetworks.com/ COPYRIGHT
This program is free software licensed under the... The BSD License The full text of the license can be found in the LICENSE file included with this module. SEE ALSO
Geo::Point, Net::GPSD, Net::GPSD::Point, Geo::ECEF, Geo::Functions, Geo::Forward, Geo::Inverse, Geo::Distance, Geo::Ellipsoids, Geo::WebService::Elevation::USGS, DateTime perl v5.10.1 2010-01-30 GPS::Point(3pm)
All times are GMT -4. The time now is 09:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy