PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : zwei text dateien gleichzeitig in perl



mr-sansibar
12-05-2006, 11:57
hallo!
kann mir jemand ein tip geben, wie ich zwei textfiles mit perl script nach bestimmten einträgen absuchen kann.
für eins habe ich schon.


grüße

Caveman
12-05-2006, 12:15
Text-Datei öffnen - Eintrag suchen - Text-Datei schließen.
Text-Datei2 öffnen - Eintrag suchen - Text-Datei2 schließen.

Zeig doch mal deinen bisherigen Code!

mr-sansibar
12-05-2006, 12:36
use strict;
use warnings;
use Getopt::Long;

# the cmd-line-arg --output
my $output = 0;
GetOptions(
'output=s' => \$output,
);


my $write_file = "c:/trxlogfile.txt";


# print usage, if no logFile is
# given as cmd-line-arg

die "usage: TrxLogParser.pl [--output FILE] logFile\n"
unless $ARGV[0];



open( OUT, ">$write_file" ) || die "Datei nicht gefunden";;



# the lines and the errorFound-flag
my @lines;
my $errorFound = 0;


my $FrontEndException = 0;
my $SocketException = 0;
my $ArrayIndexOutOfBoundsException = 0;
my $NullPointerException = 0;
my $LockedPinException = 0;
my $AuthenticationException = 0;
my $BusinessServiceException = 0;
my $IllegalStateException = 0;
my $NumberFormatException = 0;
my $Exception = 0;
my $NoSuchElementException = 0;
my $RemoteException = 0;
my $SQLException = 0;
my $IOException = 0;
my $FileNotFoundException = 0;


while ( <> ) {


#füge die zeilen von datei in array
push @lines, $_;


# wenn ein leere zeile gefunden wurde
# und errorFound-flag is gesetzt,
# dann gebe das letzte schnippel aus.
# Und all die Zeit ein leere zeile gefunden wurde
# resete errorFound und zeilen-array
if ( /^\s*$/ ) {
print OUT @lines if $errorFound eq 1;
$errorFound = 0;
@lines = '';
}


#wenn 'Severity: Error' gefunden
#setzet errorFound-flag
$errorFound = 1 if /Severity: Error/;

$FrontEndException++ if m/FrontEndException/;
$SocketException++ if m/socketException/;
$ArrayIndexOutOfBoundsException++ if m/ArrayIndexOutOfBoundsException/;
$NullPointerException++ if m/NullPointerException/;
$LockedPinException++ if m/LockedPinException/;
$AuthenticationException++ if m/AuthenticationException/;
$BusinessServiceException++ if m/\.BusinessServiceException/;
$IllegalStateException++ if m/IllegalStateException/;
$NumberFormatException++ if m/NumberFormatException/;
$Exception++ if m/\.Exception/;
$NoSuchElementException++ if m/NoSuchElementException/;
$RemoteException++ if m/RemoteException/;
$SQLException++ if m/SQLException/;
$IOException++ if m/IOException/;
$FileNotFoundException++ if m/FileNotFoundException/;

}

print OUT "FrontEndException: $FrontEndException\n
SocketException: $SocketException\n
ArrayIndexOutOfBoundsException: $ArrayIndexOutOfBoundsException\n
NullPointerException: $NullPointerException\n
LockedPinException: $LockedPinException\n
AuthenticationException: $AuthenticationException\n
BusinessServiceException: $BusinessServiceException\n
IllegalStateException: $IllegalStateException\n
NumberFormatException: $NumberFormatException\n
Exception: $Exception\n
NoSuchElementException: $NoSuchElementException\n
RemoteException: $RemoteException\n
SQLException: $SQLException\n
IOException: $IOException\n
FileNotFoundException: $FileNotFoundException\n";




# close the handle
close OUT;

Caveman
12-05-2006, 12:47
Ich weiß noch immer nicht, was Du beabsichtigst.
Gibt es irgendwelche Fehlermeldungen?
Wo liegt das Problem?

und benutze bitte
Die Code-Umgebung - wie hier

mr-sansibar
12-05-2006, 14:09
Der obiger script funktioniert.

mein problem ist, wie kann ich zwei files gleichzeitig lesen und auswerten.

Caveman
12-05-2006, 14:59
Mit zwei Dateideskriptoren zum Beispiel.




open(EINS, "<$fileeins");
open(ZWEI, "<$filezwei");

my @eins = <EINS>;
my @zwei = <ZWEI>;

close(EINS);
close(ZWEI);

#Auswertung der Arrays

mr-sansibar
12-05-2006, 15:56
Danke!
er soll die beiden dateien lesen und anschließend nach einer verarbeitung in zwei verschiedene datei rein schreiben.

grüße