1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
opendir(my $dir, '/home/users/perl/test/') or die "$!";
my @files = readdir($dir);
foreach my $file(@files){
next unless ($file =~/\.xml/);
open(my $txt, '<', $file) or die "$!";
my $new_filename = $txt;
open(my $out, '>', $new_filename) or die "$!";
while (<$txt>) {
chomp;
$_ =~ s/.*<ENCC>.*//;
print $out "$_\n";
}
}
perl -p -i.orig -e 's/.*<ENCC>.*//' *.xml *.XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ ll
total 4
-rw-r--r-- 1 linuxer users 21 Nov 4 13:42 a.xml
$ cat a.xml
hallo
du<ENCC>
welt.
$ perl -p -i.orig -e 's/.*<ENCC>.*//' *.xml *.XML
Can't open *.XML: No such file or directory, <> line 3.
$ ll
total 8
-rw-r--r-- 1 linuxer users 13 Nov 4 13:43 a.xml
-rw-r--r-- 1 linuxer users 21 Nov 4 13:42 a.xml.orig
$ cat a.xml
hallo
welt.
$ cat a.xml.orig
hallo
du<ENCC>
welt.
$