Thread ip mit regexp aus einer Datei filtern: wie filtert man aus einer log datei ips (33 answers)
Opened by misterx at 2005-03-28 16:35

renee
 2005-03-30 14:47
#53011 #53011
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/perl
use warnings;
use strict;
use Getopt::Long;

my ($filterPassword, $filterIp, $file, $file2);
my $help = 0;

# z.B. program.pl -p password -i 127.0.0.1 -file datei.txt
# oder: program.pl -h
GetOptions(
"password=s" => \$filterPassword,
"ip=s" => \$filterIp,
"file=s" => \$file,
"file2=s" => \$file2,
"help" => \$help,
);

if ($help) {
# &PrintHelp....
exit 1;
} # if

# vielleicht hier noch ueberpruefen, ob $filterPassword und $filterIp gesetzt sind....

unless (open (LOG, "<", $file)) {
die "Error: couldn't open '$file': $!\n";
} # unless

my %filteredLines;
while (<LOG>) {
chomp($_);
my ($ip, $pass) = split(/ /, $_);
if ($pass eq $filterPassword and $ip eq $filterIp) {
$filteredLines{$_} = 1;
} # if
} # while
close (LOG);

open(FILE2,"<$file2") or die $!;
while(<FILE2>){
chomp $_;
my ($ip, $pass) = split(/ /, $_);
if ($pass eq $filterPassword and $ip eq $filterIp) {
print $_,"\n" if($filteredLines{$_});
} # if
}
close FILE2;


Das funktioniert mit den beiden .txt-Dateien, die Du gepostet hast...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread ip mit regexp aus einer Datei filtern: wie filtert man aus einer log datei ips