in reply to Split file based on field
(Disclaimer: probably not the most optimal solution :)
#!/usr/bin/perl -w use strict; my %data; my $header; while (<DATA>) { chomp; if (/Usr/) { $header = $_; next; } my ($timestamp, $rest) = $_ =~ /(\d{2}-\d{2}-\d{4}:\d{2})\s+(.*)/; push @{ $data{$header}{$timestamp} }, $rest; } foreach $header (keys %data) { foreach my $timestamp (keys %{$data{$header}}) { print "$header\n"; print "$timestamp\t$_\n" for @{$data{$header}{$timestamp}}; } } __DATA__ Usr1369***12556 06-01-0101:00 1169 <snipped off> 06-01-0101:00 2396 <snipped off> 06-01-0103:12 1169 <snipped off> 06-01-0103:12 2569 <snipped off> 06-01-0301:00 1169 <snipped off> 06-01-0301:00 2396 <snipped off>
Output:
Usr1369***12556 06-01-0103:12 1169 <snipped off> 06-01-0103:12 2569 <snipped off> Usr1369***12556 06-01-0101:00 1169 <snipped off> 06-01-0101:00 2396 <snipped off> Usr1369***12556 06-01-0301:00 1169 <snipped off> 06-01-0301:00 2396 <snipped off>
Cheers,
Darren :)
|
|---|