#!/usr/bin/perl use warnings; use strict; my $path = "/ist/egal"; my $infile = "input.txt"; my $outfile = "output.csv"; my $found = ""; my $count = ""; my @Dealer = (); my $firstNR = ""; my $secNR = ""; my $thirdNR = ""; open(IN, "<$path/$infile") || die "Cannot open file $infile!\n"; while() { chomp; my $line = $_; if($line =~ /^(# suchmuster1)(\d+)(suchmuster2)/) { $firstNR = $2; $found = 2; } elsif($line =~ /^(suchmuster3)(.+)/) { $secNR = $2; } elsif($line =~ /^(suchmuster4)(test)/i) { $thirdNR = $2; } if($found eq "2") { my $new_line = $firstNR.";".$secNR.";".$thirdNR.";"; push(@Dealer, $new_line); $found = ""; $firstNR = ""; $secNR = ""; } } close(IN); open(OUT, ">>$path/$outfile") || die "Cannot open and write file $outfile!\n"; foreach my $zeile (@Dealer) { print OUT $zeile."\n"; $count++; } close(OUT); print "Habe $count Datensaetze gefunden\n";