etwa so in der art?
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
#! /usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
my ($filterPassword, $filterIp, $file);
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,
"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 (undef, $pass, $ip) = split(/ /, $_);
if ($pass eq $filterPassword and $ip eq $filterIp) {
print "gefiltert: $_\n";
push (@filteredLines, $_);
} # if
} # while
close (LOG);
foreach (@filteredLines) {
print "$_\n";
} # foreach
oder als einzeiler:
perl -ne "@cols=split(/ /); print if $cols[1] eq 'geheim' and $cols[2] eq '127.0.0.1'" file.txt
(Bis man sich an das genaue Parameterformat erinnert, ist der Einzeiler wohl schon zwei Mal getippt...)\n\n
<!--EDIT|Strat|1112166938-->