How can i read the html and modify the tag in it.
For example: /var/www/html/test.html
has the following content:
<h2>
test1
</h2>
<h2>
test2
</h2>
<h2>
test3
</h2>
I need to iterate over <h2>
and add name
attribute to it.
Requested result:
<h2 name="1">
test1
</h2>
<h2 name="2">
test2
</h2>
<h2 name="3">
test3
</h2>
I tried :
file=/var/www/html/test.html
awk -v source_str="<h2>" -v repl_str="<h2 name=\"$count\">" '{
gsub(source_str,repl_str)
print
}' $file > '/tmp/test1'
mv '/tmp/test1' $file