jaffinito34 has asked for the wisdom of the Perl Monks concerning the following question:
My script is attempting to read a log file with common log format. An example of the file is below:
66.249.65.107 - - [08/Oct/2007:04:54:20 -0400] "GET /support.html HTTP +/1.1" 200 11179
To read the file, I used a while loop and split is using spaces:
#opening log file open (LOGG, '<', 'IN-access.log'); #reading log file and assigning values while ($lines = <LOGG>){ ($remoteIP,$rfc,$userID,$dateTime,$requestType,$statusCode,$sizeOf +File) = split ' ', $lines; print "$statusCode $sizeOfFile\n"; }
However, the split function is actually splitting the spaces inside the data (ie 08/Oct/2007:04:54:20 -0400 <-- this is supposed to be the dateTime variable but because there's a space, its actually two variables according to the script) Any help or reference to help is appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splitting a file using "common log format" help
by toolic (Bishop) on Nov 10, 2012 at 21:08 UTC | |
|
Re: [SOLVED] Splitting a file using "common log format" help
by trizen (Hermit) on Nov 10, 2012 at 23:20 UTC |