Hier ist ein Perl-Skript, das die Arbeit erledigt (soweit ich es verstehe):
#!/usr/bin/perl use strict; use warnings; my $config = 'config.txt'; # give the full path my $list = 'list.txt'; # give the full path my $outfile = 'outfile.txt'; # give the full path # read list file and store in a hash open my $fhl, '<', $list or die "unable to open '$list': $!"; my %users; while(my $line = <$fhl>) { next if $. < 3; # skip first 2 lines (header) my ($user, $name) = split(/\s+/, $line); $users{$user} = $name if $user and $name; } close $fhl; open my $fhc, '<', $config or die "unable to open '$config': $!"; open my $out, '>', $outfile or die "unable to open '$outfile': $!"; # read config line by line while(my $line = <$fhc>) { # loop on all users while( my ($u,$n) = each(%users)) { # print outputfile if user found print $out "$u:$n found line $.\n" if $line =~ /\b($u|$n)\b/; } }
Ausgabedatei für gegebenes Beispiel
test38:confidential2 found line 30 test47:confidential3 found line 32