Hello
I have a log file which I'm looking to extract certain lines containing keywords so far I have managed to produce the script below which extracts any line containg words EventEstablished and Primay into a text file output as below
11/06/12 09:54:04.549 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:08.752 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:11.330 Trc 04542 EventEstablished sent to [3280] (00002a29 Primary Telephony Server 170.20.10.11:4193)
11/06/12 09:54:11.330 Trc 04542 EventEstablished sent to [3280] (00002a29 Primary Telephony Server 170.20.10.11:4193)
11/06/12 09:54:12.705 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:12.986 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:13.033 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:15.158 Trc 04542 EventEstablished sent to [3280] (00002a29 Primary Telephony Server 170.20.10.11:4193)
The script I use is below:
# Usage: perl Find.pl infile outfile
use strict;
use warnings;
my ($qfn_in, $qfn_out) = @ARGV;
open(my $fh_in, '<', $qfn_in)
or die("Unable to read file \"$qfn_in\": $!\n");
open(my $fh_out, '>', $qfn_out)
or die("Unable to create file \"$qfn_out\": $!\n");
while (<$fh_in>) {
if (/EventEstablished/ and /Portrait/) {
print $fh_out $_;
}
}
Now this is a very basic script I've been trying to enhance it but can't work out quite how yet but I'd like to add the following
1) Ability to add additional lines to extract and include in the output file when additional keywords are availiable, e.g. to also extract lines containing words RequestAgentLogin received
2) Add a header to the output file
3) Display Output file to include only cetain values out of the extracted line and strip down only IP address
i.e. what I would like the output file to produce is something like
Date Time Event IP Address
11/06/12 09:54:04.549 EventEstablished 170.20.10.11
11/06/12 09:54:08.752 EventEstablished 170.20.10.11
11/06/12 09:54:11.330 EventEstablished 170.20.10.41
11/06/12 09:58:11.330 RequestAgentLogin 170.20.10.28
Any help would be greatly appreciated
Thanks
M
I have a log file which I'm looking to extract certain lines containing keywords so far I have managed to produce the script below which extracts any line containg words EventEstablished and Primay into a text file output as below
11/06/12 09:54:04.549 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:08.752 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:11.330 Trc 04542 EventEstablished sent to [3280] (00002a29 Primary Telephony Server 170.20.10.11:4193)
11/06/12 09:54:11.330 Trc 04542 EventEstablished sent to [3280] (00002a29 Primary Telephony Server 170.20.10.11:4193)
11/06/12 09:54:12.705 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:12.986 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:13.033 Trc 04542 EventEstablished sent to [1560] (00002816 Primary Telephony Server 170.20.10.11:4140)
11/06/12 09:54:15.158 Trc 04542 EventEstablished sent to [3280] (00002a29 Primary Telephony Server 170.20.10.11:4193)
The script I use is below:
# Usage: perl Find.pl infile outfile
use strict;
use warnings;
my ($qfn_in, $qfn_out) = @ARGV;
open(my $fh_in, '<', $qfn_in)
or die("Unable to read file \"$qfn_in\": $!\n");
open(my $fh_out, '>', $qfn_out)
or die("Unable to create file \"$qfn_out\": $!\n");
while (<$fh_in>) {
if (/EventEstablished/ and /Portrait/) {
print $fh_out $_;
}
}
Now this is a very basic script I've been trying to enhance it but can't work out quite how yet but I'd like to add the following
1) Ability to add additional lines to extract and include in the output file when additional keywords are availiable, e.g. to also extract lines containing words RequestAgentLogin received
2) Add a header to the output file
3) Display Output file to include only cetain values out of the extracted line and strip down only IP address
i.e. what I would like the output file to produce is something like
Date Time Event IP Address
11/06/12 09:54:04.549 EventEstablished 170.20.10.11
11/06/12 09:54:08.752 EventEstablished 170.20.10.11
11/06/12 09:54:11.330 EventEstablished 170.20.10.41
11/06/12 09:58:11.330 RequestAgentLogin 170.20.10.28
Any help would be greatly appreciated
Thanks
M