I have a text file that looks like:
Event,1stEcIo,RxPower,Channel,Longitude,Latitude 1sec CDMA Event DtiC(0),-5.36,,,-88.150782,41.940351 Generic Scanner PN Measurement DtiC(0),,-83.35999999999997,384,-88.150 +782,41.940351 1sec CDMA Event DtiC(0),-6.36,,,-88.150782,41.940351 Generic Scanner PN Measurement DtiC(0),,-83.35999999999997,384,-88.150 +80400000001,41.940331 Generic Scanner PN Measurement DtiC(0),,-85.35999999999996,384,-88.150 +82600000001,41.940311 1sec CDMA Event DtiC(0),-7.36,,,-88.150848,41.940291 Generic Scanner PN Measurement DtiC(0),,-84.35999999999996,384,-88.150 +86533333333,41.94028566666667 Generic Scanner PN Measurement DtiC(0),,-88.36000000000001,384,-88.150 +88266666666,41.940280333333334

I need to write a Perl script to change it to this log format:
null,null,Ec,channel,long,lat 0,0,-75.2,384,-87606306,41798374

I need to combine the "1sec CDMA Event DtiC(0)" and "Generic Scanner PN Measurement DtiC(0)" rows. Every time either row repeats twice in a row, I need to average them together. So I should end up with alternating "1sec CDMA Event DtiC(0)" and "Generic Scanner PN Measurement DtiC(0)" rows.

Then I need to add the RxPower from "Generic Scanner PN Measurement DtiC(0)" to the 1stEcIo from "1sec CDMA Event DtiC(0)" and then average those two coordinates.

Also the lat longs need the decimal places taken out and truncated to 8 digits long. I should end up with a log file like:

null,null,Ec,channel,long,lat
0,0,-70.5,384,-87777777,41111111

Where:
Ec = RxPower + 1stEcIo
Channel allways = 384
Lat & Long = the average lat/long for all datapoints combined to make row.

Here's some of my code that I started:

$LOGFILE = @ARGS; open(LOGFILE) or die("Could not open log file."); foreach $line (<LOGFILE>) { #This is where I'm lost, I don't know where to beging on chomping all +this data. }

How would you guys recommend chomping all this data?

In reply to Manipulating Text File in Perl by awohld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.