Thread Matching von bis in einer Datei (24 answers)
Opened by Rambo at 2009-05-04 14:54

Linuxer
 2009-05-04 19:06
#121150 #121150
User since
2006-01-27
3870 Artikel
HausmeisterIn

user image
Wenn Deine Suchstrings immer feste Strings sind, dann brauchst Du keine Regex-Maschine anwerfen, sondern kannst index() verwenden:

Beispiel:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl
use strict;
use warnings;

my $output_file = '/dev/null';

my $search       = 'test 1';
my $end_of_block = '[end.message]';

open my $outfh, '>>', $output_file or die "$output_file: open failed: $!\n";

while ( my $line = <DATA> ) {
    
    if ( index( $line, $search, 0 ) >= 0 .. index( $line, $end_of_block, 0 ) >= 0 ) {
        print $outfh $line or die "$output_file: print failed: $!\n";
    }
}

close $output_file or die "$output_file: close failed: $!\n";

__DATA__
test 1 von Computer 4711
MHz = 500
RAM = 256
Screen = 17 Zoll
[end.message]
test 2 von Computer 0815
MHz = 1500
RAM = 512
Screen = 21 Zoll
[end.message]
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Matching von bis in einer Datei