Have script which parses a CSV file which looks like the following
Date and Time Number Total I/O /sec More columns
08 09 2007 18:00:00 00:00 2.2733333
08 09 2007 18:00:00 00:01 0.033333335
08 09 2007 18:00:00 00:02 0.036666665
08 09 2007 18:00:00 00:03 1.1433333
08 09 2007 18:00:00 00:04 0
08 09 2007 18:00:00 00:05 0
08 09 2007 18:00:00 00:06 10.453333
08 09 2007 18:00:00 00:07 2.26
08 09 2007 18:00:00 00:08 1.0166667
08 09 2007 18:00:00 00:09 441.14
08 09 2007 18:00:00 00:0A 0.006666667
.....
08 09 2007 18:05:00 00:00 2.9333334
08 09 2007 18:05:00 00:01 0.39333335
08 09 2007 18:05:00 00:02 0.096666664
08 09 2007 18:05:00 00:03 1.2966666
08 09 2007 18:05:00 00:04 0.093333334
08 09 2007 18:05:00 00:05 1.8733333
08 09 2007 18:05:00 00:06 8.63
08 09 2007 18:05:00 00:07 2.9
08 09 2007 18:05:00 00:08 1.27
08 09 2007 18:05:00 00:09 1.1766666
08 09 2007 18:05:00 00:0A 0.33
.....
etc etc
The thing that changes is the time stamp, the number column has the format xx:yy, where xx is fixed starting at 00 until yy(hex) gets to FF in hex, and then it turns to 01 and so on. It then starts from 01:00
The script works, but not in the format that I want. Currently, it is producing the data in following format with only the columns I want
Date and Time Number Total I/O /sec
08 09 2007 18:00:00 00:00 2.2733333
08 09 2007 18:00:00 00:01 0.033333335
08 09 2007 18:00:00 00:02 0.036666665
08 09 2007 18:00:00 00:03 1.1433333
08 09 2007 18:00:00 00:04 0
08 09 2007 18:00:00 00:05 0
08 09 2007 18:00:00 00:06 10.453333
08 09 2007 18:00:00 00:07 2.26
08 09 2007 18:00:00 00:08 1.0166667
08 09 2007 18:00:00 00:09 441.14
08 09 2007 18:00:00 00:0A 0.006666667
.....
08 09 2007 18:05:00 00:00 2.9333334
08 09 2007 18:05:00 00:01 0.39333335
08 09 2007 18:05:00 00:02 0.096666664
08 09 2007 18:05:00 00:03 1.2966666
08 09 2007 18:05:00 00:04 0.093333334
08 09 2007 18:05:00 00:05 1.8733333
08 09 2007 18:05:00 00:06 8.63
08 09 2007 18:05:00 00:07 2.9
08 09 2007 18:05:00 00:08 1.27
08 09 2007 18:05:00 00:09 1.1766666
08 09 2007 18:05:00 00:0A 0.33
.....
But what I want is to have all the same number values together eg
Date and Time Number Total I/O /sec
08 09 2007 18:00:00 00:00 2.2733333
08 09 2007 18:05:00 00:00 2.9333334
08 09 2007 18:10:00 00:00 3.2300034
....
08 09 2007 18:00:00 00:01 0.033333335
08 09 2007 18:05:00 00:01 0.39333335
08 09 2007 18:10:00 00:01 0.5500034
Any ideas how I can do this?
Any help would be appreciated as it is frustrating me no end.
Date and Time Number Total I/O /sec More columns
08 09 2007 18:00:00 00:00 2.2733333
08 09 2007 18:00:00 00:01 0.033333335
08 09 2007 18:00:00 00:02 0.036666665
08 09 2007 18:00:00 00:03 1.1433333
08 09 2007 18:00:00 00:04 0
08 09 2007 18:00:00 00:05 0
08 09 2007 18:00:00 00:06 10.453333
08 09 2007 18:00:00 00:07 2.26
08 09 2007 18:00:00 00:08 1.0166667
08 09 2007 18:00:00 00:09 441.14
08 09 2007 18:00:00 00:0A 0.006666667
.....
08 09 2007 18:05:00 00:00 2.9333334
08 09 2007 18:05:00 00:01 0.39333335
08 09 2007 18:05:00 00:02 0.096666664
08 09 2007 18:05:00 00:03 1.2966666
08 09 2007 18:05:00 00:04 0.093333334
08 09 2007 18:05:00 00:05 1.8733333
08 09 2007 18:05:00 00:06 8.63
08 09 2007 18:05:00 00:07 2.9
08 09 2007 18:05:00 00:08 1.27
08 09 2007 18:05:00 00:09 1.1766666
08 09 2007 18:05:00 00:0A 0.33
.....
etc etc
The thing that changes is the time stamp, the number column has the format xx:yy, where xx is fixed starting at 00 until yy(hex) gets to FF in hex, and then it turns to 01 and so on. It then starts from 01:00
Code:
#!/usr/bin/perl
use Text::CSV_XS;
my $file = 'mycsv.csv';
my $csv = Text::CSV_XS->new();
open (CSV, "<", $file) or die $!;
while (<CSV>) {
next if ($. == 1);
if ($csv->parse($_)) {
@columns = $csv->fields();
$i = 0;
while ($i <= 10) {
$hexval = uc(sprintf("%x",$i)); #uppercase hex
if (length($hexval) eq 1){ # if $hexval is length of 1, then pad with '0'
$hexval = uc(sprintf("0%x",$i));
}
$val = "00".":".$hexval; #concat 00:$hexval
if ($columns[1] eq $val){
print "$columns[0]\t$columns[1]\t$columns[2]\n";
# want to process some data here
}
$i++;
}
}
else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;
The script works, but not in the format that I want. Currently, it is producing the data in following format with only the columns I want
Date and Time Number Total I/O /sec
08 09 2007 18:00:00 00:00 2.2733333
08 09 2007 18:00:00 00:01 0.033333335
08 09 2007 18:00:00 00:02 0.036666665
08 09 2007 18:00:00 00:03 1.1433333
08 09 2007 18:00:00 00:04 0
08 09 2007 18:00:00 00:05 0
08 09 2007 18:00:00 00:06 10.453333
08 09 2007 18:00:00 00:07 2.26
08 09 2007 18:00:00 00:08 1.0166667
08 09 2007 18:00:00 00:09 441.14
08 09 2007 18:00:00 00:0A 0.006666667
.....
08 09 2007 18:05:00 00:00 2.9333334
08 09 2007 18:05:00 00:01 0.39333335
08 09 2007 18:05:00 00:02 0.096666664
08 09 2007 18:05:00 00:03 1.2966666
08 09 2007 18:05:00 00:04 0.093333334
08 09 2007 18:05:00 00:05 1.8733333
08 09 2007 18:05:00 00:06 8.63
08 09 2007 18:05:00 00:07 2.9
08 09 2007 18:05:00 00:08 1.27
08 09 2007 18:05:00 00:09 1.1766666
08 09 2007 18:05:00 00:0A 0.33
.....
But what I want is to have all the same number values together eg
Date and Time Number Total I/O /sec
08 09 2007 18:00:00 00:00 2.2733333
08 09 2007 18:05:00 00:00 2.9333334
08 09 2007 18:10:00 00:00 3.2300034
....
08 09 2007 18:00:00 00:01 0.033333335
08 09 2007 18:05:00 00:01 0.39333335
08 09 2007 18:10:00 00:01 0.5500034
Any ideas how I can do this?
Any help would be appreciated as it is frustrating me no end.