I have a file with a character I would like to replace, but I also want to have each instance of the character(s) to be replaced, be iterated with a number inside the sting replacement.
SomeFile.txt
[H
A
[H
B
[H
C
I want to replace "[H" with "</pre></div><div id=cat$n><pre>
" where $n is an interator for the number of replacements. So the first replacement would be 1, 2, 3, 4, n++ and so on.
Is there a way to to do this with sed
?
sed
using a loop, but do you absolutely needsed
? Perl would suit to this problem better.perl -pe 's/^\[H$/"<\/pre><\/div><div id=cat".++$n."><pre>"/e' file
.cat filename | grep "\[H" | wc -l
Im not saying it wouldnt be useful, but I already have that info. Heres what the file was editing: nanocluster.umeche.maine.edu/ascii/star/starWarz.html