Thread Datei lesen und umformatieren (2 answers)
Opened by Andreas at 2010-09-17 08:18

payx
 2010-09-17 11:15
#141364 #141364
User since
2006-05-04
564 Artikel
BenutzerIn

user image
Hallo Andreas,

unklar ist mir, wie legroj0 zu legmom1 werden soll und wo das neue Datum herkommt.

Das ganze sollte sich hieraus jedenfalls entwickeln lassen:

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
#!/usr/bin/perl

use strict;
use warnings;

open my $outFH, ">", "umformatieren.txt" or die $!;

while (<DATA>) {
    chomp;
    if (m/\|/) {
        my @in = split /\|/;
        my @out;
        ($out[0] = $in[0]) =~ s/^\w(\d+)/[1.$1]/;
        $out[1]  = $in[3]; # oder statt $in[3] halt die neue Zeichenfolge
        ($out[2] = $in[4]) =~ s/(\d{4})(\d{2})(\d{2})/$3.$2.$1/; # oder statt $in[4] das neue Datum
        print $outFH join "|", @out;
        print $outFH "\n";
    } elsif ($_) {
        print $outFH $_, "\n";
    }
}

close $outFH or die $!;

__DATA__
A01|10279011|AC|legmab0|20080904|PGT
neues Programm

A02|10279011|AD|legroj0|20081126|PGT
Programmänderung

HTH
Grüße
payx

View full thread Datei lesen und umformatieren