I have comma separated CSV file. And there are 5 columns date,delta time, bits, bitsin, bitsout.
Task is
1) sort the file by date
2) ignore the bits
3) compare the bitsin and bitsout and keep the highest one
4) sort the higest one
5) print all above four steps comma separated
I have done first 3 steps and i dont know how i can perform step 4 any body can help me
Raw Data File Contents
12/6/2006 00:02:23,301,1151.78735352,677.26245117,474.52490234
12/6/2006 00:07:22,299,1108.97656250,641.49835205,467.47827148
12/6/2006 00:12:22,300,1020.15997314,590.40002441,429.76000977
12/6/2006 00:17:23,301,981.26245117,562.01995850,419.24252319
OutPut File
1/6/2006 00:03:46 300,641.06665039,477.60000610,641.06665039
1/6/2006 00:08:46 300,563.78668213,425.60000610,563.78668213
1/6/2006 00:13:47 301,505.99334717,430.72424316,505.99334717
Wanting Output
1/6/2006 00:03:46 300,641.06665039,477.60000610,641.06665039 ,505.99334717
1/6/2006 00:08:46 300,563.78668213,425.60000610,563.78668213 ,563.78668213
1/6/2006 00:13:47 301,505.99334717,430.72424316,505.99334717 ,641.06665039
open(RAW,"raw_data") or die ("could not open the file $!");
while(<RAW>) {
chomp;
next if /^(\s)*$/;
my @this_record = split(/,/,$_);
push(@records,\@this_record);
}
my @sorted = sort{$a->[0] <=> $b->[0]} @records;
foreach $record (@sorted) {
if($record->[3] >= $record->[4]) {
$final = $record->[3];
}
else {
$final = $record->[4];
}
print "$record->[0] $record->[1],$record->[3],$record->[4],$final\n";
}
close(RAW);
2006-07-17 Retitled by Corion, as per Monastery guidelines
Original title: 'Sorting'
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.