in reply to Re^3: Pull users with multiple search
in thread Pull users with multiple search
As suggested, I tried to work on myself and have come up with following code, so far I have implemented the following steps :
1. Define two hashes: %users and %searches
2. Process the logfile line by line. For each line, use a regex to see if it matches the BIND or RESULT form, and extract the relevant fields ($conn, $uid, etc.) if it does. Also:
2a.If it is a BIND line: Add an entry to the %users hash, with $conn as the key and $uid as the value.
2b. If it is a RESULT line: Add relevant information (about the timestamp of the search) to the value of the %searches entry that belongs to the key $conn.At this point, I am not sure how to compare the three occurrence. Please help me.
#!/usr/bin/perl #use warnings; #use strict; use 5.010; open(IN, "logs.txt") or die "can not open file"; my %users; my %searches; while (<IN>){ if (/BIND/){ my ($conn) = /conn=(\d+)\s/; my ($uid) = /uid=(.*?),/; $users{$conn} .= exists $users{$conn} ? " $uid, " : $uid; print %users; } if (/SRCH=Q/){ my ($conn1) = /conn=(\d+)\s/; my (@line) = split(" ",$_); my $timestamp = "$line[0]\n"; $searches{$conn1} = exists $searches{$conn1} ? " $timestam +p," : $timestamp; print %searches; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Pull users with multiple search
by johnprince1980 (Initiate) on Jun 10, 2013 at 19:42 UTC |