hi I am trying to replace strings in a file, test.txt with strings like these :
<g
id="g16526">
<g
<g
id="gnnnnn">
<g
and turn them into
<g
id="gg1">
<g
...
<g
id="ggn">
<g
using this perl script
#!C:/Strawberry/perl
open(FILE, "<test.txt") || die "File not found";
my @lines = <FILE>;
close(FILE);
my $string = '<g
id=';
my $string2 = '<g
<g';
my $anything = ".*";
my $replace = 'gg';
my @newlines;
my $counter = 1;
foreach(@lines) {
$_ =~ s/\Qstring$anything\Q$string2/$string$replace$string2$counter/g;
$counter++;
push(@newlines,$_);
}
open(FILE, ">test.txt") || die "File not found";
print FILE @newlines;
close(FILE);
but it doesnt work, any suggestions appreciated