Thread 5 Zeilen ab jener mit bestimten Wort aus Datei löschen (6 answers)
Opened by donlenardo at 2012-02-20 15:47

hugenyn
 2012-02-20 21:46
#156240 #156240
User since
2010-10-05
65 Artikel
BenutzerIn

user image
Mein Versuch an Deinem Code.
Man kann die Arrays auch weglassen, direkt lesen, in eine zweite Datei schreiben und diese dann umbenennen.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
use strict;
use 5.010;
use warnings;

my $EMPTYname = "EMPTY";

my ( @dataEempty, @output );

open BOUNDARY, "< /home/wolf/Dokumente/emty.txt";

        @dataEempty = <BOUNDARY>;

close BOUNDARY;

foreach  ( @dataEempty ) {

        my $lineEmpty = shift @dataEempty;

        unless ( $lineEmpty =~ /$EMPTYname/ ) {

                &schreibe ( $lineEmpty, \@output )

        } else {

                &schreibe ( $lineEmpty, \@output );

                last

        }

}

my $weiter = 0;

foreach my $lineEmpty(@dataEempty) {

        if ( $lineEmpty =~ /\}/ )  {

                &schreibe ( $lineEmpty, \@output );

                $weiter = 1 # Umschalter

        } else {

                &schreibe ( $lineEmpty, \@output ) if $weiter == 1 

        }

}

open OUT, "> /home/wolf/Dokumente/boundary";

foreach my $line (@output) {

        print OUT $line

}

close OUT;

sub schreibe {

  my ($lineEmpty, $ar) = shift;

  print "Es wird geschrieben: = $lineEmpty \n";

  push @$ar, $lineEmpty

}

Last edited: 2012-02-21 00:47:16 +0100 (CET)

View full thread 5 Zeilen ab jener mit bestimten Wort aus Datei löschen