Thread Suchen und ersetzen (6 answers)
Opened by pernox77 at 2012-06-25 08:00

renee
 2012-06-25 15:58
#159360 #159360
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Wenn die Datei nicht zu groß ist kannst Du das in eine Variable einlesen:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl

use strict;
use warnings;

my $file = '/path/to/file';
my $content = do { local (@ARGV,$/) = $file; <> };

my $keyword = 'test';
my $replace = 'hallo';
$content =~ s/$keyword \s+ [^\s]+/$keyword $replace/xg;
print $content;


Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
$ cat file.txt 
Das ist ein test mit Leerzeichen
Ein test


mit Zeilenumbrüchen

$ perl replace.pl
Das ist ein test hallo Leerzeichen
Ein test hallo Zeilenumbrüchen

$
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Suchen und ersetzen