Thread Keywords in Textdateien zählen (9 answers)
Opened by Nik at 2016-04-20 01:53

Gast wer
 2016-04-20 08:59
#184492 #184492
Grundlage ungetestet:
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
32
33
34
35
36
37
38
#!/usr/bin/perl
use strict;
use warnings;

my @keywords = qw( übertroffen erreicht motiviert);
my @files = glob('/path/to/files');

my $regexp = join('|', map{ qr/\Q$_\E/ }sort{ length($b) <=> length($a) }@keywords );

for my $file (@files) {

  if( open(my $fh, '<', $file) ) {

    print "\n\n$file\n";

    my $lc = 0;
    while( my $line = <$fh> ) {
      lc++;

      if($line =~/(\d{10})/) {
        print "Zeile $lc: $1\n";
      }

      my $rc = 1;
      while( $line=~/^(.*?)($regexp)// ) {
        $rc+=length($1);
        print "Spalte $rc/ Zeile $lc: $2\n";
        $rc+=length($2);
      }

    }
    close($fh);
  }
  else {
    warn "$file ERROR OPEN $!\n";
    next;
  }
}

Last edited: 2016-04-20 09:38:11 +0200 (CEST)

View full thread Keywords in Textdateien zählen