Code:
# date(1) time(2) ty source(4) destination(5) header info (6)
# 2014-01-31 16:14:38.108331 IP 80.34.103.251 > 1.2.22.222: ICMP echo request [snip]
^
With the
split function I separate the long line on the colon followed by the space into two parts.
A second [b]split] on a space or blank then separates the first part into the fields that I am interested in.
Code:
sub read_simple {
my ($leading, $info);
my ($date, $time, $type, $source, $direction, $dest);
while (<DATA>) {
($leading, $info) = split(/: /);
print "Leading: ", $leading, "\n";
print "Info : ", $info, "\n";
($date, $time, $type, $source, $direction, $dest) = split( / /, $leading);
show_raw($date, $time, $type, $source, $dest, $info);
export( $date, $time, $type, $source, $dest, $info);
}
}
The following output demonstrates this two stages approach:
- Stage 1
Code:
Leading: 2014-01-31 16:14:30.938665 IP 80.25.124.114 > 1.2.22.222
Info : ICMP echo request, id 0, seq 0, length 64
- Stage 2
Code:
Date : 2014-01-31
Time : 16:14:30.938665
Type : IP
Source IP : 80.25.124.114
Destination IP : 1.2.22.222
Info : ICMP echo request, id 0, seq 0, length 64
=============================