You are not logged in.

#1 2015-01-23 13:29:54

kopiersperre
Member
Registered: 2011-03-22
Posts: 48

Chemical formula processing in command-line

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

#2 2015-01-23 14:25:43

a821
Member
Registered: 2012-10-31
Posts: 383

Re: Chemical formula processing in command-line

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

#3 2015-01-23 14:58:41

kopiersperre
Member
Registered: 2011-03-22
Posts: 48

Re: Chemical formula processing in command-line

Exactly, thanks a lot.

Offline

Board footer

Powered by FluxBB