Aligning Contents in Text File

Dear All,

I have been working on aligning contents of a text file but I am having problems. I have the following text file called "tempThermody.therm" and I need to align all the last values from row 3 to appear as the 80th column. The values that will appear as the 80th columns are 1,2,3 and 4. I have achieved this as shown in the file "thermody.therm" below. The problem is that some of the first row values do not start from column 1 and the application I am running requires that they begin from column 1. Apart from that, the values in between columns 1 and 80 need to start from certain specific columns which I have also achieved. Please how can I adjust the file tempThermody.therm:

THERMO
300.0 1500.0 5000.0
Ar                     Ar    1           g   300.00  5000.00  1000.00       1
2.5000                 0.0000 0.0000      0.0000   0.0000                   2
-745.3750                 4.3660 2.5000      0.0000   0.0000                3
0.0000                 0.0000 -745.3750      4.3660                   4
N2                      N    2           g   300.00  5000.00  1000.00       1
3.2987                 0.0014 -0.0000      0.0000  -0.0000                   2
-1020.8999                 3.9504 2.9266      0.0015  -0.0000                3
0.0000                -0.0000 -922.7977      5.9805                   4
H                      H    1           g   200.00  3500.00  1000.00       1
2.5000                 0.0000 -0.0000      0.0000  -0.0000                   2
25473.6599                -0.4467 2.5000     -0.0000   0.0000                3
-0.0000                 0.0000 25473.6599     -0.4467                   4
H2                      H    2           g   200.00  3500.00  1000.00       1
2.3443                 0.0080 -0.0000      0.0000  -0.0000                   2
-917.9352                 0.6830 3.3373     -0.0000   0.0000                3
-0.0000                 0.0000 -950.1589     -3.2050                   4
O                      O    1           g   200.00  3500.00  1000.00       1
3.1683                -0.0033 0.0000     -0.0000   0.0000                   2
29122.2592                 2.0519 2.5694     -0.0001   0.0000                3
-0.0000                 0.0000 29217.5791      4.7843                   4
O2                      O    2           g   200.00  3500.00  1000.00       1
3.7825                -0.0030 0.0000     -0.0000   0.0000                   2
-1063.9436                 3.6577 3.2825      0.0015  -0.0000                3
0.0000                -0.0000 -1088.4577      5.4532                   4
OH                      H    1           g   200.00  3500.00  1000.00       1
3.9920                -0.0024 0.0000     -0.0000   0.0000                   2
3615.0806                -0.1039 3.0929      0.0005   0.0000                3
-0.0000                 0.0000 3858.6570      4.4767                   4
OH                      O    1           g   200.00  3500.00  1000.00       1
3.9920                -0.0024 0.0000     -0.0000   0.0000                   2
3615.0806                -0.1039 3.0929      0.0005   0.0000                3
-0.0000                 0.0000 3858.6570      4.4767                   4
H2O                      H    2           g   200.00  3500.00  1000.00       1
4.1986                -0.0020 0.0000     -0.0000   0.0000                   2
-30293.7267                -0.8490 3.0340      0.0022  -0.0000                3
-0.0000                 0.0000 -30004.2971      4.9668                   4
H2O                      O    1           g   200.00  3500.00  1000.00       1
4.1986                -0.0020 0.0000     -0.0000   0.0000                   2
-30293.7267                -0.8490 3.0340      0.0022  -0.0000                3
-0.0000                 0.0000 -30004.2971      4.9668                   4
HO2                      H    1           g   200.00  3500.00  1000.00       1
4.3018                -0.0047 0.0000     -0.0000   0.0000                   2
294.8080                 3.7167 4.0172      0.0022  -0.0000                3
0.0000                -0.0000 111.8567      3.7851                   4
HO2                      O    2           g   200.00  3500.00  1000.00       1
4.3018                -0.0047 0.0000     -0.0000   0.0000                   2
294.8080                 3.7167 4.0172      0.0022  -0.0000                3
0.0000                -0.0000 111.8567      3.7851                   4
H2O2                      H    2           g   200.00  3500.00  1000.00       1
4.2761                -0.0005 0.0000     -0.0000   0.0000                   2
-17702.5821                 3.4351 4.1650      0.0049  -0.0000                3
0.0000                -0.0000 -17861.7877      2.9162                   4
H2O2                      O    2           g   200.00  3500.00  1000.00       1
4.2761                -0.0005 0.0000     -0.0000   0.0000                   2
-17702.5821                 3.4351 4.1650      0.0049  -0.0000                3
0.0000                -0.0000 -17861.7877      2.9162                   4
END


I used this code:
sed -e :a -e 's/^.\{30,79\}$/ &/;ta'  tempThermody.therm > thermody.therm

To produce the file thermody.therm as:
THERMO
300.0 1500.0 5000.0
   Ar                     Ar    1           g   300.00  5000.00  1000.00       1
   2.5000                 0.0000 0.0000      0.0000   0.0000                   2
   -745.3750                 4.3660 2.5000      0.0000   0.0000                3
         0.0000                 0.0000 -745.3750      4.3660                   4
   N2                      N    2           g   300.00  5000.00  1000.00       1
  3.2987                 0.0014 -0.0000      0.0000  -0.0000                   2
  -1020.8999                 3.9504 2.9266      0.0015  -0.0000                3
         0.0000                -0.0000 -922.7977      5.9805                   4
    H                      H    1           g   200.00  3500.00  1000.00       1
  2.5000                 0.0000 -0.0000      0.0000  -0.0000                   2
  25473.6599                -0.4467 2.5000     -0.0000   0.0000                3
       -0.0000                 0.0000 25473.6599     -0.4467                   4
   H2                      H    2           g   200.00  3500.00  1000.00       1
  2.3443                 0.0080 -0.0000      0.0000  -0.0000                   2
   -917.9352                 0.6830 3.3373     -0.0000   0.0000                3
        -0.0000                 0.0000 -950.1589     -3.2050                   4
    O                      O    1           g   200.00  3500.00  1000.00       1
   3.1683                -0.0033 0.0000     -0.0000   0.0000                   2
  29122.2592                 2.0519 2.5694     -0.0001   0.0000                3
       -0.0000                 0.0000 29217.5791      4.7843                   4
   O2                      O    2           g   200.00  3500.00  1000.00       1
   3.7825                -0.0030 0.0000     -0.0000   0.0000                   2
  -1063.9436                 3.6577 3.2825      0.0015  -0.0000                3
        0.0000                -0.0000 -1088.4577      5.4532                   4
   OH                      H    1           g   200.00  3500.00  1000.00       1
   3.9920                -0.0024 0.0000     -0.0000   0.0000                   2
   3615.0806                -0.1039 3.0929      0.0005   0.0000                3
        -0.0000                 0.0000 3858.6570      4.4767                   4
   OH                      O    1           g   200.00  3500.00  1000.00       1
   3.9920                -0.0024 0.0000     -0.0000   0.0000                   2
   3615.0806                -0.1039 3.0929      0.0005   0.0000                3
        -0.0000                 0.0000 3858.6570      4.4767                   4
  H2O                      H    2           g   200.00  3500.00  1000.00       1
   4.1986                -0.0020 0.0000     -0.0000   0.0000                   2
 -30293.7267                -0.8490 3.0340      0.0022  -0.0000                3
      -0.0000                 0.0000 -30004.2971      4.9668                   4
  H2O                      O    1           g   200.00  3500.00  1000.00       1
   4.1986                -0.0020 0.0000     -0.0000   0.0000                   2
 -30293.7267                -0.8490 3.0340      0.0022  -0.0000                3
      -0.0000                 0.0000 -30004.2971      4.9668                   4
  HO2                      H    1           g   200.00  3500.00  1000.00       1
   4.3018                -0.0047 0.0000     -0.0000   0.0000                   2
    294.8080                 3.7167 4.0172      0.0022  -0.0000                3
          0.0000                -0.0000 111.8567      3.7851                   4
  HO2                      O    2           g   200.00  3500.00  1000.00       1
   4.3018                -0.0047 0.0000     -0.0000   0.0000                   2
    294.8080                 3.7167 4.0172      0.0022  -0.0000                3
          0.0000                -0.0000 111.8567      3.7851                   4
 H2O2                      H    2           g   200.00  3500.00  1000.00       1
   4.2761                -0.0005 0.0000     -0.0000   0.0000                   2
 -17702.5821                 3.4351 4.1650      0.0049  -0.0000                3
       0.0000                -0.0000 -17861.7877      2.9162                   4
 H2O2                      O    2           g   200.00  3500.00  1000.00       1
   4.2761                -0.0005 0.0000     -0.0000   0.0000                   2
 -17702.5821                 3.4351 4.1650      0.0049  -0.0000                3
       0.0000                -0.0000 -17861.7877      2.9162                   4
END

This produced the 80th columns required except that some of the first row values do not start from column 1. Please see the two files as attachments.

Any help is appreciated.
Kind regards
Sign In or Register to comment.