I have a long xml file that contains many times the string
<div type="something">
I need to add only to those strings the text "id="NUMBER" where NUMBER is a value starting from 1 and incrementing by 1. My output should be
<div id="1" type="something">
<div id="2" type="something">
<div id="3" type="something">
...
I would preferably use Perl; can anyone help me?
Thank you, Stefania
I tried this:
use strict;
use warnings;
my $str = "<div id=\"";
my $i = 0;
$str =~ s/<div id=\"/'<div id="'.++$i/ eg;
print "$str";