I want to pull data that I will need to reformat from a simulation file I am working with to prepare it as input for running other simulations. The target data is an optimized chemical z-matrix. The only difference from the example in the link is that the digits are stored as variables under the z-matrix.
I'm working with files which can span thousands to hundreds of thousands of lines, and have throughout it other intermediate z-matrices which are extremely similar to my target data. However, there is a unique leading line and a line after the data I need so the data in between those two lines should be relatively simple to extract. Here is an example:
Final structure in terms of initial Z-matrix:
Cl
C,1,B1
C,2,B2,1,A2
H,2,B3,1,A3,3,D3,0
H,2,B4,1,A4,3,D4,0
C,3,B5,2,A5,1,D5,0
C,6,B6,3,A6,2,D6,0
C,7,B7,6,A7,3,D7,0
H,3,B8,2,A8,1,D8,0
H,3,B9,2,A9,1,D9,0
H,7,B10,6,A10,3,D10,0
H,7,B11,6,A11,3,D11,0
H,8,B12,7,A12,6,D12,0
H,8,B13,7,A13,6,D13,0
H,8,B14,7,A14,6,D14,0
O,6,B15,3,A15,2,D15,0
Variables:
B1=1.81746475
B2=1.52136867
A2=110.80057513
B3=1.0898967
A3=106.92512231
D3=-121.94499481
B4=1.08989406
A4=106.92581701
D4=121.94497834
B5=1.52808963
A5=111.92359259
D5=179.99770382
B6=1.523193
A6=116.49970868
D6=179.97424974
B7=1.52739317
A7=113.56269053
D7=179.98802896
B8=1.09816794
A8=110.50682514
D8=58.2854688
B9=1.09816384
A9=110.50888758
D9=-58.28349045
B10=1.10022643
A10=107.84652382
D10=56.40290615
B11=1.10022793
A11=107.84460667
D11=-56.42958848
B12=1.09398015
A12=110.97242167
D12=-59.62466169
B13=1.09473047
A13=110.53459142
D13=179.99742235
B14=1.09397826
A14=110.9720435
D14=59.61905862
B15=1.21736254
A15=121.22780588
D15=-0.02140167
1\1\GINC-C0959\FOpt\RB3LYP\6-31G(d)\C5H9Cl1O1\SKYLERS\10-Sep-2013\0\\#
I also need to reformat this data, replacing the commas in the first part with spaces and the variables need to be left indented letters followed by right indented numbers. I also want to set up this script to write this data to a new file based on the name of the input file.
My goals in summary:
- open file abc.out
- start reading after "final structure in terms of initial Z-matrix:"
- reformat Z-matrix
- reformat variables
- write to file abc.cm
So far these are some of the awk portions i was thinking of using:
{FS=","};{OFS=" "};{print $0}
{FS="="};{printf "%-4s%13.8f", $1, $2}
What I still haven't figured out:
- How do I write to a file based on the input file name?
- How do I read only between the first and last lines?
- How should I split this at "Variables:"?