in reply to sorting logfiles by timestamp
G'day jasonl,
You show no indication of what <data2> contains. I assume they're not unique values as you've used it as a key for an array (@{$myHash{$data2}{info}}). You don't say how many elements this array might hold, if you want to sort on <data2> nor whether <data2> needs to appear in the output.
A representative, unordered sample of the input as well as how you'd expect that to be output would have been helpful.
The following script may provide some help in formulating your solution:
#!/usr/bin/env perl -l use strict; use warnings; use Time::Piece; my %myHash; my $format = '%m/%d/%Y %H:%M:%S'; while (<DATA>) { my ($date, $time, $data1, $data2) = split; my $sort_key = Time::Piece->strptime("$date $time", $format)->epoc +h; push @{$myHash{$data2}{info}}, "$sort_key:$date,$time,$data1"; } for my $key (sort keys %myHash) { print "$_,$key" for map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ split /:/, $myHash{$key}{info}[$_], 2 ] } 0 .. $#{$myHash{$key}{info}}; } __DATA__ 01/14/2014 23:44:14 A Y 01/14/2014 23:44:12 B Y 01/14/2014 23:44:13 C X 01/14/2014 23:44:12 D X
Output:
01/14/2014,23:44:12,D,X 01/14/2014,23:44:13,C,X 01/14/2014,23:44:12,B,Y 01/14/2014,23:44:14,A,Y
If you provide a better description of your problem, a better solution can probably be provided. The guidelines in "How do I post a question effectively?" may help you with this.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting logfiles by timestamp
by jasonl (Acolyte) on Jan 22, 2014 at 23:28 UTC | |
by kcott (Archbishop) on Jan 23, 2014 at 14:43 UTC | |
|
Re^2: sorting logfiles by timestamp
by jasonl (Acolyte) on Jan 21, 2014 at 16:15 UTC | |
by kcott (Archbishop) on Jan 21, 2014 at 18:29 UTC | |
by Jim (Curate) on Jan 21, 2014 at 22:57 UTC | |
by kcott (Archbishop) on Jan 22, 2014 at 14:37 UTC | |
by Jim (Curate) on Jan 22, 2014 at 18:04 UTC | |
| |
by Anonymous Monk on Jan 22, 2014 at 14:05 UTC |