perl-Lesen-Datei und greifen spezifische Linien

Ich habe eine text Datei und ich packen möchte bestimmte Zeilen, beginnend mit einem Muster und endet mit einem bestimmten Muster.
Beispiel:

Text
Text
Startpattern
print this line
Print this line
print this line
Endpattern
Text
Text
Text

Start-Muster und das Ende-Muster gedruckt werden soll. Mein Erster Versuch war nicht wirklich erfolgreich:


my $LOGFILE = "/var/log/logfile";
my @array;
# open the file (or die trying)

open(LOGFILE) or die("Could not open log file.");
foreach $line () {
  if($line =~  m/Sstartpattern/i){
    print $line;
    foreach $line2 () {
      if(!$line =~  m/Endpattern/i){
        print $line2;
      }
    }
  }
}
close(LOGFILE);

Dank im Voraus für Eure Hilfe.

Ich weiß, dass tief unten, wenn Sie schrieb: "could not open log file"., Sie soll schreiben, "Konnte nicht geöffnet werden $LOGFILE: $!".

InformationsquelleAutor Stefan | 2011-03-22

Schreibe einen Kommentar