Leser: 1
|< 1 2 3 >| | 29 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
my $file = '/path/to/file';
my $line_start = 'BB';
my $search = 'wort3';
open my $fh,'<',$file or die $!;
while(my $line = <$fh>){
next unless $line =~ /^\Q$line_start\E/;
print "yes\n" if $line =~ /\Q$search\E/;
}
close $fh;
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
32
33
34
35
use strict;
use warnings;
sub create_file ($$) {
my ($lines, $file) = @_;
open my $fh, '>', $file or die $!;
for (1..$lines) {
print $fh sprintf("%0".length($lines)."d", $_), " wort1 wort2 wort3\n";
}
close $fh;
}
sub search_in_file ($$$) {
my ($line, $file, $search) = @_;
open my $fh, '<', $file or die $!;
my $first_line = <$fh>;
my $length = length($first_line);
seek($fh, $length*(--$line), 0);
my $this_line = <$fh>;
return 1 if $this_line =~ /$search/;
return undef;
}
my $lines = 100000;
my $search = 'wort1';
my $line = 50000;
my $file = './test.txt';
create_file($lines, $file);
if (search_in_file($line, $file, $search)) {
print "HIT\n";
} else {
print "NO HIT\n";
}
|< 1 2 3 >| | 29 Einträge, 3 Seiten |