You are not logged in.
I would like to transform chemical formulas to wiki-syntaxed ones.
For example C8H10N4O2 to C<sub>8</sub>H<sub>10</sub>N<sub>4</sub>O<sub>2</sub>
Is this possible with awk or any other cli tool?
Offline
Something like this?
one formula per line in a file
$ cat test.txt
C10HN23O2
C10H30N23O2P2S
C10HN23O2PS2
then
$ < test.txt perl -anle 's#(\d+)#<sub>$1</sub>#g ; print'
C<sub>10</sub>HN<sub>23</sub>O<sub>2</sub>
C<sub>10</sub>H<sub>30</sub>N<sub>23</sub>O<sub>2</sub>P<sub>2</sub>S
C<sub>10</sub>HN<sub>23</sub>O<sub>2</sub>PS<sub>2</sub>
Offline
Exactly, thanks a lot.
Offline