#! /usr/bin/perl use strict; use warnings; print $ARGV[0]; my $file = $ARGV[0]; my ($in,$suffix) = $ARGV[0] =~ /(.*?)(\.[^\.]+)$/; my $out = $in.'.cut'.$suffix; my $count_ = 1; my $datensatz = ''; { open(my $outfh,">$out") or die $!; open(my $fh,"<$file") or die $!; while(my $entry = <$fh>){ $entry =~ s/\r?\n//g; if($entry =~ /^\s*?#/){ print $outfh $entry,"\n"; } else{ if($entry =~ /^\s*?$/){ $count_++; } else{ $datensatz .= $entry."\n"; } if($count_ % 3 == 0){ $datensatz = getDatensatz($datensatz); print $outfh $datensatz; $count_ = 1; $datensatz = ''; } } } if($datensatz){ $datensatz = getDatensatz($datensatz); print $outfh $datensatz; } close $fh; close $outfh; } sub getDatensatz{ my ($entry) = @_; my $bool = 0; my $warte_auf_flanke = 0; my $set = ''; my @fallend; for my $line(split(/\r?\n/,$entry)){ chomp $line; my $wert = (split(/\s+/,$line))[-1]; if($wert > 4.8) { $warte_auf_flanke = 1; } if($warte_auf_flanke and $wert < 4) { $warte_auf_flanke = 0; $bool = 1; } unless($bool){ push(@fallend,$_[-1]); } else{ $set .= $line."\n"; } } my $last = ( split /\n/, $set )[-1]; $set .= ( $last . "\n" ) x 9; $set .= $_ . "\n" for (@fallend); $set .= "\n\n"; return $set; }