#!/usr/bin/perl use strict; use warnings 'all'; # dateinamen my $inputfile = '/var/log/mail.log.1'; my $outputfile = '/var/www/alle_rejects.txt'; # oeffne inputfile open(my$fhin, '<', $inputfile) or die "$inputfile: $!"; # array f�r die ausgabe my @output; # lies zeile f�r zeile while (my$line = <$fhin>) { if ($line =~ m/\breject\b/) { # wenn der Suchstring "reject" vorkommt, # und "from" gefunden wird, # wird das ausgabearray erweitert if ( $line =~ m/from\s*(.*?):/ ) { push(@output, substr( $line, 0, 15 ) .' : '. $1) } } } # inputfile schliessen close $fhin; # ausgabearray bearbeiten unshift(@output, $#output+2); # oeffne outputfile open(my$fhout, '>', $outputfile) or die "$outputfile: $!"; # daten rausschreiben map { print $fhout "$_$/" } @output; # outputfile schliessen close $fhout;