Hi all.
I have a bit of a problem here. I’m a bit new to awk, but I think that he is the one for the following task.
I have files in the following format:
C
C 1 1.3756312
C 2 1.3879733 1 120.0957745
C 3 1.3850912 2 119.6454502 1 7.8601452 0
C 4 1.3892896 3 119.7264098 2 -6.4720895 0
C 5 1.3844873 4 120.0924064 3 -1.2289029 0
N 3 1.4348439 2 119.2949612 1 -166.5566349 0
C 7 1.3250991 3 123.0481206 2 18.5755546 0
...
An I need to reformat then into this:
c
c 1 cc2
c 2 cc3 1 ccc3
c 3 cc4 2 ccc4 1 dih4
c 4 cc5 3 ccc5 2 dih5
c 5 cc6 4 ccc6 3 dih6
n 2 nc7 3 ncc7 4 dih7
c 7 cn8 2 cnc8 3 dih8
c 8 cc9 7 ccn9 2 dih9
n 9 nc10 8 ncc10 7 dih10
...
cc2 1.385627
cc3 1.387278
ccc3 120.462
cc4 1.387224
ccc4 119.224
dih4 11.852
cc5 1.384238
ccc5 119.249
dih5 0.237
cc6 1.387992
ccc6 120.570
dih6 -10.931
nc7 1.442256
ncc7 118.545
dih7 -156.703
cn8 1.381867
cnc8 130.485
...
In case anyone is wondering, yes, I’m dealing with zmatrix here. But it’s about a thousand of them easily.
That’s really not a simple task. Is there any way of doing so in a script?
Btw, I have some freedom in the “variable names”. o, as in the 7th column of the first section in second file I can have just “dih” strings, I can also have “bon” and “ang” in the 3rd and 5th columns.