Greetings Monks,
I'm a bit of a klutz with regular expressions, but I've taken a shot at making this script which parses log entries for a Pure Ftpd server I run. I'm looking for ways to improve it's efficiency and readability. The log entries are separated by carraige returns and the elements by single spaces.
#!/usr/bin/perl use strict; use warnings; my $data = 'Jul 30 19:39:06 server pure-ftpd: (user@68.158.32.189) [NOTICE] /home/shows//Genesis/Genesis 1978-06-24 FLAC/genesis1978-06-24-prefm-d1t04.flac downloaded (71074015 bytes, 60.83KB/sec) Jul 30 19:39:23 server pure-ftpd: (user@68.17.66.125) [NOTICE] /home/shows//Simon and Garfunkel/Simon and Garfunkel 2003-10-16/SG2003-10-16-d2t03.shn downloaded (2075533 bytes, 115.25KB/sec)'; my @lines = split "\n", $data; foreach my $line (@lines) { $line =~ m/^(\w+)\s(\d+)\s(\S+)\s\w+\s\D+\s\D(\w+) \x40(\d+\W\d+\W\d+\W\d+)\D\s\S+\s(.*) \s+\w+\s+\S?(\d+)\s\w+\S\s(\d+\W\d+)/; print "Month is: $1\n"; print "Day is: $2\n"; print "Time is: $3\n"; print "User is: $4\n"; print "IP is: $5\n"; print "File is: $6\n"; print "Size is : $7\n"; print "Speed is : $8\n"; } 1;
In reply to Pure Ftpd log regex by redhotpenguin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |