| SoftOver |
| Home Humor Puzzles Links Ruby News bLogs Books |
|
Log Scan
Ruby
Recently I had to find all IP addresses in the access log for the first 10 minutes after 1PM. Here is one-liner I used: ruby -n -e '$_.scan(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*2007:13:0/){ puts $1}' < access.log | sort -u
Please note that I did not care about IP address correctness, I'd use much longer regexp if I did: /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).*2007:13:0/ |