Reformatting a file to a tabular form

I have a file named output_hw3.txt. Here is a snippet of what the file looks like:

Format:
MassCol  T   Pg   Pe
Ne  N_HI  N_HII  N_H-
N_H- / Ne
N_MetalsI: C, Si, Fe, Mg, Ni, Cr, Ca, Na, K, He
N_MetalsII: C, Si, Fe, Mg, Ni, Cr, Ca, Na, K, He

    0.0024755001       3854.1699       68.180943    0.0055848958
  1.0500383e+010  1.1807884e+014       10675330.       5194.1882
  4.9466655e-007
  3.9078841e+010  1.6780051e+009  3.2307887e+008  1.9018621e+008       45107395.
       465253.11       122020.51       24138.090       136.76409  1.0048511e+013
       5259778.1  2.5137943e+009  2.9240896e+009  4.2968103e+009  1.6507297e+008
       54795651.  2.7027856e+008  2.5266461e+008       15586272.  1.5453476e-008
 
    0.0028962200       3877.2000       79.768532    0.0065355518
  1.2214761e+010  1.3732618e+014       13734106.       6871.3347
  5.6254352e-007
  4.5448482e+010  1.9481881e+009  3.7652000e+008  2.2238807e+008       52635488.
       553831.48       146780.86       29524.341       169.83916  1.1686459e+013
       6487486.5  2.9268917e+009  3.3999503e+009  4.9960072e+009  1.9180513e+008
       63714826.  3.1433020e+008  2.9384853e+008       18126887.  2.4199651e-008
 
    0.0037139100       3915.8701       102.28959    0.0083958570
  1.5536660e+010  1.7435846e+014       20800045.       10692.008
  6.8817933e-007
  5.7703492e+010  2.4524978e+009  4.7561646e+008  2.8232271e+008       66696851.
       723915.40       195196.35       40359.374       238.07417  1.4837906e+013
       9163782.4  3.7372281e+009  4.3192416e+009  6.3432994e+009  2.4366124e+008
       80875851.  3.9908571e+008  3.7308678e+008       23015081.  5.0716648e-008
 
    0.0046118600       3947.3101       127.02119     0.010417204
  1.9123652e+010  2.1479037e+014       29043651.       15736.395
  8.2287601e-007
  7.1083521e+010  3.0288537e+009  5.9173706e+008  3.5296248e+008       83033012.
       926869.89       253426.93       53564.573       322.38843  1.8278663e+013
       12102883.  4.5962056e+009  5.3149990e+009  7.8090729e+009  2.9929391e+008
       99595039.  4.9161660e+008  4.5959790e+008       28352011.  9.1791041e-008
 
    0.0056288200       3975.8301       155.03060     0.012695719
  2.3139310e+010  2.6027325e+014       39168732.       22464.859
  9.7085258e-007
  8.6134928e+010  3.6894746e+009  7.2663182e+008  4.3543499e+008  1.0195274e+008
       1168237.2       323445.05       69720.113       427.24736  2.2149257e+013
       15530204.  5.5502271e+009  6.4308836e+009  9.4549500e+009  3.6133371e+008
  1.2063966e+008  5.9570238e+008  5.5691512e+008       34355647.  1.5607984e-007
 
    0.0067911400       4002.6799       187.04355     0.015291357
  2.7683187e+010  3.1191184e+014       51725805.       31417.781
  1.1349048e-006
  1.0322325e+011  4.4489642e+009  8.8339126e+008  5.3172407e+008  1.2389550e+008
       1455385.3       407675.28       89493.581       557.68247  2.6543702e+013
       19583423.  6.6239078e+009  7.6941856e+009  1.1320928e+010  4.3130765e+008
  1.4451938e+008  7.1387055e+008  6.6740195e+008       41171811.  2.5560374e-007
 
    0.0081296498       4028.8799       223.90918     0.018277681
  3.2874388e+010  3.7096044e+014       67604092.       43320.018
  1.3177437e-006
  1.2276345e+011  5.3201074e+009  1.0644403e+009  6.4341176e+008  1.4923245e+008
       1795269.1       508573.06       113620.01       719.56028  3.1568739e+013
       24481534.  7.8489908e+009  9.1369737e+009  1.3453088e+010  5.1107726e+008
  1.7181425e+008  8.4899100e+008  7.9374187e+008       48966068.  4.1098201e-007
 
    0.0096769696       4054.6001       266.52591     0.021725405
  3.8827620e+010  4.3876450e+014       87631797.       59121.667
  1.5226704e-006
  1.4520068e+011  6.3250446e+009  1.2748174e+009  7.7373318e+008  1.7865581e+008
       2199474.7       629926.80       143145.46       920.87998  3.7338866e+013
       30395251.  9.2510981e+009  1.0791209e+010  1.5899321e+010  6.0234515e+008
  2.0314235e+008  1.0041410e+009  9.3881306e+008       57916004.  6.5121204e-007
 
     0.011470700       4080.7000       315.92934     0.025731598
  4.5693351e+010  5.1676774e+014  1.1358422e+008       80047.594
  1.7518434e-006
  1.7101243e+011  7.4703197e+009  1.5149362e+009  9.2302942e+008  2.1231428e+008
       2672894.1       773932.85       178890.47       1169.0980  4.3976944e+013
       37731366.  1.0874939e+010  1.2696180e+010  1.8714149e+010  7.0753250e+008
  2.3917446e+008  1.1826244e+009  1.1057043e+009       68212187.  1.0321742e-006
 
     0.013555000       4106.8999       373.33574     0.030390032
  5.3621376e+010  6.0677202e+014  1.4685526e+008       107758.92
  2.0096263e-006
  2.0079485e+011  8.7882576e+009  1.7923354e+009  1.0961429e+009  2.5123212e+008
       3232767.3       946256.84       222443.64       1476.6362  5.1636312e+013
       46739041.  1.2752154e+010  1.4893899e+010  2.1961200e+010  8.2882234e+008
  2.8073661e+008  1.3885620e+009  1.2982700e+009       80092450.  1.6289847e-006
 
     0.015978400       4133.1699       440.08173     0.035808204
  6.2779838e+010  7.1070633e+014  1.8936745e+008       144399.33
  2.3000909e-006
  2.3518609e+011  1.0308570e+010  2.1137489e+009  1.2974556e+009  2.9634697e+008
       3896237.0       1152799.9       275559.28       1857.8168  6.0481124e+013
       57767792.  1.4921511e+010  1.7430680e+010  2.5709392e+010  9.6871063e+008
  3.2871441e+008  1.6263651e+009  1.5206364e+009       93811402.  2.5589079e-006
 
     0.018796200       4159.7598       517.69040     0.042117948
  7.3370227e+010  8.3069569e+014  2.4408534e+008       192735.62
  2.6268914e-006
  2.7488898e+011  1.2054030e+010  2.4836861e+009  1.5299619e+009  3.4834643e+008
       4677801.3       1399023.2       340038.03       2328.4025  7.0692224e+013
       71371071.  1.7435676e+010  2.0360452e+010  3.0036484e+010  1.1302923e+009
  3.8408790e+008  1.9008947e+009  1.7773493e+009  1.0964954e+008  4.0174817e-006
 
     0.022074500       4186.7998       607.98230     0.049475272
  8.5630191e+010  9.6927902e+014  3.1483510e+008       256421.75
  2.9945250e-006
  3.2074324e+011  1.4054055e+010  2.9081776e+009  1.7976401e+009  4.0812872e+008
       5595844.8       1691781.6       418131.16       2908.2081  8.2485672e+013
       88224463.  2.0355362e+010  2.3747004e+010  3.5034975e+010  1.3171885e+009
  4.4802689e+008  2.2179579e+009  2.0738397e+009  1.2794196e+008  6.3167364e-006
 
     0.025894601       4214.6299       713.19662     0.058082891
  9.9864170e+010  1.1295094e+015  4.0753168e+008       340305.82
  3.4076868e-006
  3.7375839e+011  1.6332961e+010  3.3911701e+009  2.1031404e+009  4.7637988e+008
       6666522.6       2037719.8       512257.76       3619.9712  9.6121289e+013
  1.0936974e+008  2.3764639e+010  2.7670351e+010  4.0818234e+010  1.5341477e+009
  5.2194409e+008  2.5845399e+009  2.4166388e+009  1.4909168e+008  9.9983581e-006
 
     0.030349299       4242.5400       835.88922     0.068124432
  1.1635843e+011  1.3151121e+015  5.2618276e+008       450919.43
  3.8752622e-006
  4.3516697e+011  1.8972737e+010  3.9532055e+009  2.4598391e+009  5.5580780e+008
       7938323.7       2453058.9       627115.97       4502.0614  1.1191608e+014
  1.3529848e+008  2.7713761e+010  3.2212391e+010  4.7514440e+010  1.7850926e+009
  6.0753437e+008  3.0091548e+009  2.8137138e+009  1.7359036e+008  1.5752952e-005
 
     0.035545401       4271.1201       979.00177     0.079877030
  1.3551927e+011  1.5299654e+015  6.8098231e+008       596559.09
  4.4020242e-006
  5.0625110e+011  2.1993346e+010  4.5961927e+009  2.8691648e+009  6.4691444e+008
       9427812.2       2945622.2       765920.96       5587.0285  1.3020012e+014
  1.6769303e+008  3.2320451e+010  3.7477876e+010  5.5269548e+010  2.0764253e+009
  7.0659634e+008  3.5006768e+009  3.2733616e+009  2.0194994e+008  2.4930070e-005
 
     0.041610200       4299.8198       1146.0402     0.093602799
  1.5774641e+011  1.7790554e+015  8.7935460e+008       788530.31
  4.9987210e-006
  5.8866017e+011  2.5494976e+010  5.3449474e+009  3.3474099e+009  7.5300838e+008
       11197762.       3537198.5       935321.71       6931.7497  1.5139769e+014
  2.0746067e+008  3.7661522e+010  4.3579100e+010  6.4256729e+010  2.4137118e+009
  8.2140058e+008  4.0705017e+009  3.8062451e+009  2.3482850e+008  3.9292624e-005
 
     0.048685901       4328.4702       1340.9212      0.10961074
  1.8350149e+011  2.0678006e+015  1.1314741e+009       1041457.4
  5.6754708e-006
  6.8418646e+011  2.9570237e+010  6.2217238e+009  3.9093535e+009  8.7712825e+008
       13310541.       4250490.3       1142672.4       8602.0301  1.7596993e+014
  2.5590820e+008  4.3836724e+010  5.0642823e+010  7.4667112e+010  2.8035588e+009
  9.5442066e+008  4.7310154e+009  4.4239530e+009  2.7294122e+008  6.1525804e-005
 
     0.056936000       4357.2598       1568.1478      0.12828497
  2.1334539e+011  2.4022230e+015  1.4529617e+009       1374264.9
  6.4415027e-006
  7.9482115e+011  3.4294202e+010  7.2430173e+009  4.5661340e+009  1.0216681e+009
       15821460.       5107232.5       1395674.9       10671.345  2.0442930e+014
  3.1514653e+008  5.0984766e+010  5.8818155e+010  8.6718395e+010  3.2542914e+009
  1.1084196e+009  5.4959868e+009  5.1393647e+009  3.1708296e+008  9.5988064e-005
 
     0.066556700       4386.3301       1833.1240      0.15008637
  2.4794815e+011  2.7895248e+015  1.8641550e+009       1811978.5
  7.3078929e-006
  9.2294553e+011  3.9758198e+010  8.4290511e+009  5.3313981e+009  1.1895484e+009
       18798049.       6134069.6       1703854.5       13231.666  2.3738872e+014
  3.8781177e+008  5.9270001e+010  6.8282934e+010  1.0067062e+011  3.7758091e+009
  1.2867005e+009  6.3818821e+009  5.9678833e+009  3.6820429e+008   0.00014951812
 
     0.077788100       4415.6201       2142.4625      0.17555465
  2.8809886e+011  3.2386287e+015  2.3884949e+009       2388263.2
  8.2897350e-006
  1.0715102e+012  4.6100194e+010  9.8124177e+009  6.2270129e+009  1.3852869e+009
       22339965.       7369020.3       2080331.3       16407.356  2.7560751e+014
  4.7670010e+008  6.8871211e+010  7.9249938e+010  1.1684097e+011  4.3794766e+009
  1.4933394e+009  7.4090963e+009  6.9285903e+009  4.2748290e+008   0.00023232704
 
     0.090901703       4445.0298       2503.6411      0.20529339
  3.3467341e+011  3.7595598e+015  3.0538681e+009       3147161.9
  9.4036808e-006
  1.2438303e+012  5.3482532e+010  1.1432234e+010  7.2793452e+009  1.6142585e+009
       26568399.       8858627.0       2541312.2       20353.661  3.1993880e+014
  5.8494579e+008  7.9981948e+010  9.1955743e+010  1.3558404e+011  5.0777633e+009
  1.7329070e+009  8.6005402e+009  8.0429231e+009  4.9624194e+008   0.00035960091
 
      0.10621000       4474.6802       2925.2667      0.24003159
  3.8871143e+011  4.3635806e+015  3.8999632e+009       4146056.7
  1.0666156e-005
  1.4436294e+012  6.2057459e+010  1.3323564e+010  8.5123026e+009  1.8814390e+009
       31604705.       10651868.       3104879.0       25251.640  3.7134104e+014
  7.1706530e+008  9.2849791e+010  1.0667501e+011  1.5730391e+011  5.8857414e+009
  2.0105528e+009  9.9819566e+009  9.3349660e+009  5.7596790e+008   0.00055539379
 
      0.12408600       4504.6401       3417.6127      0.28063497
  4.5144267e+011  5.0640992e+015  4.9770438e+009       5461025.6
  1.2096831e-005
  1.6753400e+012  7.2012997e+010  1.5530328e+010  9.9558428e+009  2.1930097e+009
       37600018.       12809854.       3793707.7       31330.413  4.3095527e+014
  8.7851971e+008  1.0776270e+011  1.2373254e+011  1.8248012e+011  6.8210958e+009
  2.3324008e+009  1.1583989e+010  1.0833389e+010  6.6843043e+008   0.00085672217
 
      0.14495800       4534.6001       3992.4755      0.32801403
  5.2417263e+011  5.8768239e+015  6.3327477e+009       7192739.7
  1.3722082e-005
  1.9441571e+012  8.3646503e+010  1.8127944e+010  1.1661188e+010  2.5590713e+009
       44789570.       15423599.       4639905.0       38904.282  5.0011825e+014
  1.0737062e+009  1.2498097e+011  1.4348489e+011  2.1165836e+011  7.9016864e+009
  2.7055670e+009  1.3442518e+010  1.2571777e+010  7.7570268e+008    0.0013143193
 
      0.16931200       4564.4102       4663.2403      0.38321414
  6.0838399e+011  6.8193423e+015  8.0256058e+009       9472309.4
  1.5569623e-005
  2.2558970e+012  9.7279661e+010  2.1198230e+010  1.3684361e+010  2.9906056e+009
       53441188.       18599064.       5681848.8       48357.294  5.8032671e+014
  1.3079680e+009  1.4480728e+011  1.6633390e+011  2.4545095e+011  9.1478380e+009
  3.1380148e+009  1.5597713e+010  1.4587728e+010  9.0010589e+008    0.0020015281
 
      0.19773300       4594.5601       5446.0198      0.44768102
  7.0606659e+011  7.9117868e+015  1.0166562e+010       12471065.
  1.7662733e-005
  2.6172121e+012  1.1312529e+011  2.4787233e+010  1.6057832e+010  3.4944950e+009
       63758062.       22427072.       6957091.0       60102.003  6.7329393e+014
  1.5927489e+009  1.6774350e+011  1.9278718e+011  2.8459045e+011  1.0588504e+010
  3.6389629e+009  1.8095588e+010  1.6924289e+010  1.0442971e+009    0.0030457181
 
      0.23091900       4624.8301       6360.0383      0.52292465
  8.1934017e+011  9.1791653e+015  1.2853020e+010       16419484.
  2.0039886e-005
  3.0363716e+012  1.3164124e+011  2.9012205e+010  1.8862261e+010  4.0864394e+009
       76134473.       27066492.       8524645.2       74745.358  7.8114806e+014
  1.9363600e+009  1.9421958e+011  2.2341520e+011  3.2994651e+011  1.2252498e+010
  4.2197209e+009  2.0993252e+010  1.9634917e+010  1.2115768e+009    0.0046176950
 
      0.26967201       4655.4702       7427.3848      0.61086005
  9.5082170e+011  1.0649067e+016  1.6245175e+010       21616882.
  2.2734948e-005
  3.5224929e+012  1.5319155e+011  3.3959427e+010  2.2158111e+010  4.7786183e+009
       90916761.       32668546.       10445988.       92963.971  9.0623696e+014
  2.3535707e+009  2.2485090e+011  2.5889035e+011  3.8250704e+011  1.4176749e+010
  4.8928541e+009  2.4353731e+010  2.2778592e+010  1.4055860e+009    0.0069979162
 
      0.31491500       4686.5200       8673.4805      0.71490648
  1.1054005e+012  1.2353271e+016  2.0495177e+010       28506606.
  2.5788486e-005
  4.0860841e+012  1.7843823e+011  3.9808201e+010  2.6070814e+010  5.5945465e+009
  1.0874427e+008       39497328.       12822012.       115823.48  1.0512651e+015
  2.8554415e+009  2.6010362e+011  2.9990732e+011  4.4335426e+011  1.6394312e+010
  5.6725962e+009  2.8249540e+010  2.6423222e+010  1.6305187e+009     0.010585777
 
      0.36774099       4718.9199       10128.429      0.83594370
  1.2836757e+012  1.4326444e+016  2.6060371e+010       37513017.
  2.9223125e-005
  4.7385741e+012  2.0712456e+011  4.6435846e+010  3.0517285e+010  6.5221456e+009
  1.2943355e+008       47534373.       15672849.       143771.27  1.2191826e+015
  3.4875119e+009  3.0146513e+011  3.4754209e+011  5.1388858e+011  1.8978971e+010
  6.5753545e+009  3.2760082e+010  3.0642973e+010  1.8909503e+009     0.016225570
 
      0.42940199       4752.1602       11826.715      0.97787194
  1.4911174e+012  1.6611614e+016  3.3217856e+010       49352172.
  3.3097443e-005
  5.4941873e+012  2.4015959e+011  5.4087051e+010  3.5667764e+010  7.5935042e+009
  1.5384137e+008       57135722.       19136806.       178309.90  1.4136512e+015
  4.2678610e+009  3.4955388e+011  4.0273324e+011  5.9557482e+011  2.1975227e+010
  7.6204094e+009  3.7983536e+010  3.5529788e+010  2.1925591e+009     0.024985843
 
      0.50133198       4787.1802       13807.831       1.1451170
  1.7333689e+012  1.9252373e+016  4.2693632e+010       64882103.
  3.7431215e-005
  6.3672917e+012  2.7749475e+011  6.2699294e+010  4.1481973e+010  8.8043894e+009
  1.8202794e+008       68395127.       23284073.       220510.19  1.6383806e+015
  5.2579653e+009  4.0596602e+011  4.6674215e+011  6.9010984e+011  2.5464911e+010
  8.8281028e+009  4.4019638e+010  4.1176886e+010  2.5410984e+009     0.039079699
 
      0.58525503       4824.4102       16119.264       1.3429138
  2.0170878e+012  2.2301767e+016  5.5452971e+010       85239544.
  4.2258717e-005
  7.3753703e+012  3.1925722e+011  7.2256631e+010  4.7950850e+010  1.0156622e+010
  2.1418871e+008       81462763.       28208785.       271752.71  1.8978851e+015
  6.5331217e+009  4.7245749e+011  5.4104350e+011  7.9951842e+011  2.9540623e+010
  1.0223064e+010  5.0989712e+010  4.7697692e+010  2.9435689e+009     0.062345037
 
      0.68318498       4864.6899       18816.479       1.5782735
  2.3509750e+012  2.5817911e+016  7.3120711e+010  1.1189420e+008
  4.7594804e-005
  8.5375356e+012  3.6507421e+011  8.2584032e+010  5.4955500e+010  1.1633097e+010
  2.5008475e+008       96346668.       33971441.       333295.26  2.1971105e+015
  8.2171754e+009  5.5146423e+011  6.2741054e+011  9.2612790e+011  3.4322915e+010
  1.1832732e+010  5.9026837e+010  5.5216515e+010  3.4076406e+009      0.10232497
 
      0.79739702       4908.8101       21962.140       1.8600096
  2.7457429e+012  2.9863161e+016  9.8257542e+010  1.4673419e+008
  5.3440617e-005
  9.8742447e+012  4.1420621e+011  9.3403080e+010  6.2305774e+010  1.3203524e+010
  2.8915847e+008  1.1294431e+008       40604406.       406303.88  2.5413634e+015
  1.0494276e+010  6.4593951e+011  7.2783656e+011  1.0724981e+012  3.9953078e+010
  1.3686847e+010  6.8273921e+010  6.3866772e+010  3.9415440e+009      0.17403819
 
      0.93051100       4958.0400       25628.404       2.2003542
  3.2159070e+012  3.4502304e+016  1.3538889e+011  1.9217625e+008
  5.9758026e-005
  1.1406632e+013  4.6495401e+011  1.0416999e+011  6.9629677e+010  1.4803459e+010
  3.3003473e+008  1.3085559e+008       48051334.       491354.63  2.9361576e+015
  1.3676099e+010  7.5988261e+011  8.4464711e+011  1.2414630e+012  4.6610884e+010
  1.5817107e+010  7.8879732e+010  7.3787170e+010  4.5538307e+009      0.31038565
 
       1.0855401       5014.0498       29898.260       2.6166908
  3.7816791e+012  3.9800883e+016  1.9275042e+011  2.5133080e+008
  6.6460108e-005
  1.3155859e+013  5.1446007e+011  1.1406426e+011  7.6368475e+010  1.6329750e+010
  3.7041625e+008  1.4932424e+008       56138645.       588142.35  3.3870716e+015
  1.8297300e+010  8.9847813e+011  9.8046533e+011  1.4360724e+012  5.4516166e+010
  1.8256487e+010  9.0995140e+010  8.5118164e+010  5.2531539e+009      0.58899047
 
       1.2659700       5078.4199       34867.713       3.1335692
  4.4712772e+012  4.5827765e+016  2.8514746e+011  3.2833110e+008
  7.3431166e-005
  1.5143842e+013  5.5927150e+011  1.2222251e+011  8.1942539e+010  1.7665228e+010
  4.0771882e+008  1.6744988e+008       64630742.       695887.07  3.8999671e+015
  2.5243246e+010  1.0676243e+012  1.1380489e+012  1.6595234e+012  6.3908702e+010
  2.1039809e+010  1.0477879e+011  9.8007398e+010  6.0486068e+009       1.2028315
 
       1.4757500       5153.0400       40645.535       3.7884527
  5.3274486e+012  5.2647865e+016  4.4074269e+011  4.2885792e+008
  8.0499682e-005
  1.7390530e+013  5.9518928e+011  1.2775291e+011  8.5764537e+010  1.8677170e+010
  4.3908658e+008  1.8418250e+008       73220411.       813235.30  4.4803708e+015
  3.6058893e+010  1.2738256e+012  1.3200755e+012  1.9148711e+012  7.5036815e+010
  2.4200321e+010  1.2038044e+011  1.1259415e+011  6.9487631e+009       2.6746154
 
       1.7190200       5240.6299       47345.749       4.6443060
  6.4218218e+012  6.0301108e+016  7.1662070e+011  5.6116593e+008
  8.7384226e-005
  1.9906315e+013  6.1712941e+011  1.2974949e+011  8.7249705e+010  1.9216275e+010
  4.6138778e+008  1.9830969e+008       81516978.       938183.26  5.1316853e+015
  5.3589125e+010  1.5235854e+012  1.5285507e+012  2.2042196e+012  8.8120973e+010
  2.7759866e+010  1.3789287e+011  1.2896439e+011  7.9589027e+009       6.5768871
 
       1.9996099       5342.9399       55073.838       5.8055633
  7.8738110e+012  6.8799790e+016  1.2220002e+012  7.3858286e+008
  9.3802463e-005
  2.2690579e+013  6.2300808e+011  1.2826322e+011  8.6470504e+010  1.9248922e+010
  4.7431573e+008  2.0967542e+008       89477181.       1072320.2  5.8549662e+015
  8.2556282e+010  1.8194279e+012  1.7637646e+012  2.5279680e+012  1.0321688e+011
  3.1724558e+010  1.5734464e+011  1.4714469e+011  9.0806613e+009       17.872776
 
       2.3191600       5463.9600       63874.978       7.4806713
  9.9209664e+012  7.8025357e+016  2.1881943e+012  9.8417576e+008
  9.9201602e-005
  2.5695439e+013  6.1065818e+011  1.2333738e+011  8.3486067e+010  1.8740587e+010
  4.7748418e+008  2.1813915e+008       97098308.       1218944.2  6.6401442e+015
  1.3167928e+011  2.1593197e+012  2.0224202e+012  2.8815607e+012  1.2014845e+011
  3.6039408e+010  1.7846494e+011  1.6688185e+011  1.0298417e+010       54.303126
 
       2.6769700       5602.0098       73729.886       9.9474736
  1.2867372e+013  8.7840903e+016  4.0179500e+012  1.3306869e+009
   0.00010341560
  2.8863630e+013  5.8619123e+011  1.1671644e+011  7.9469073e+010  1.7911071e+010
  4.7576451e+008  2.2560349e+008  1.0509146e+008       1388563.7  7.4756029e+015
  2.1303956e+011  2.5323035e+012  2.2990189e+012  3.2586380e+012  1.3845289e+011
  4.0635659e+010  2.0093927e+011  1.8788304e+011  1.1594141e+010       177.24047
 
       3.0606501       5800.4399       84297.315       14.935430
  1.8658542e+013  9.6987009e+016  8.4505119e+012  1.9168958e+009
   0.00010273556
  3.1728596e+013  5.2468230e+011  1.0346380e+011  7.1160558e+010  1.6003632e+010
  4.5324067e+008  2.2663394e+008  1.1218497e+008       1590602.5  8.2543138e+015
  3.7690124e+011  2.9186566e+012  2.5639114e+012  3.6146670e+012  1.5664829e+011
  4.4940635e+010  2.2189297e+011  2.0745810e+011  1.2801810e+010       812.27732
 
       3.4360199       6041.6699       94635.859       24.496538
  2.9381140e+013  1.0451681e+017  1.8219463e+013  2.8811052e+009
  9.8059682e-005
  3.3934302e+013  4.5507232e+011  8.9761973e+010  6.2605957e+010  1.3914284e+010
  4.2737761e+008  2.2778756e+008  1.2059399e+008       1854828.3  8.8959313e+015
  6.6679360e+011  3.2559213e+012  2.7849514e+012  3.9097253e+012  1.7215807e+011
  4.8495018e+010  2.3915744e+011  2.2358438e+011  1.3796769e+010       4213.7890
 
       3.7835300       6266.4302       104207.08       39.772143
  4.5991726e+013  1.1093189e+017  3.3305196e+013  4.3021467e+009
  9.3541755e-005
  3.5704195e+013  4.1840972e+011  8.3312840e+010  5.8945410e+010  1.2863094e+010
  4.2685378e+008  2.4135644e+008  1.3522688e+008       2235268.2  9.4431386e+015
  1.0252871e+012  3.5208549e+012  2.9682302e+012  4.1577322e+012  1.8465496e+011
  5.1504861e+010  2.5386896e+011  2.3733030e+011  1.4645171e+010       16426.058
 
       4.1126399       6473.7100       113271.52       61.610352
  6.8963829e+013  1.1668158e+017  5.4947166e+013  6.1795366e+009
  8.9605475e-005
  3.7185927e+013  3.9460284e+011  7.9488088e+010  5.7005763e+010  1.2194772e+010
  4.3386730e+008  2.5894709e+008  1.5215972e+008       2680163.6  9.9342787e+015
  1.4538647e+012  3.7495440e+012  3.1307665e+012  4.3789824e+012  1.9559625e+011
  5.4198829e+010  2.6706771e+011  2.4966401e+011  1.5406542e+010       52006.472
 
       4.4275799       6699.1802       121945.69       96.312170
  1.0417906e+014  1.2132591e+017  9.0447319e+013  8.8106241e+009
  8.4571931e-005
  3.8144909e+013  3.6640672e+011  7.4806351e+010  5.4447425e+010  1.1378241e+010
  4.3535213e+008  2.7543859e+008  1.6967298e+008       3193421.4  1.0332533e+016
  2.0439073e+012  3.9438742e+012  3.2641437e+012  4.5593744e+012  2.0474289e+011
  5.6387506e+010  2.7776804e+011  2.5966135e+011  1.6023767e+010       166185.83
 
       4.7248201       6953.5400       130132.37       157.88651
  1.6453564e+014  1.2462775e+017  1.4727474e+014  1.2886073e+010
  7.8317822e-005
  3.8491232e+013  3.4072422e+011  7.0770548e+010  5.2394689e+010  1.0634455e+010
  4.4054178e+008  2.9760353e+008  1.9234234e+008       3888740.2  1.0618355e+016
  2.8093039e+012  4.0887895e+012  3.3605429e+012  4.6890566e+012  2.1146511e+011
  5.7954174e+010  2.8543722e+011  2.6682623e+011  1.6466416e+010       543203.99
 
       4.9966798       7226.8799       137620.01       257.34851
  2.5804280e+014  1.2664149e+017  2.3856624e+014  1.8481012e+010
  7.1619949e-005
  3.8178966e+013  3.1134769e+011  6.5872725e+010  4.9673823e+010  9.7555402e+009
  4.3826843e+008  3.1756608e+008  2.1489786e+008       4676471.8  1.0797494e+016
  3.8183369e+012  4.1928948e+012  3.4233292e+012  4.7717688e+012  2.1609098e+011
  5.8941604e+010  2.9023779e+011  2.7130845e+011  1.6743493e+010       1762102.2
 
       5.2392201       7508.4902       144300.12       407.58102
  3.9335280e+014  1.2754803e+017  3.7865519e+014  2.5602911e+010
  6.5088925e-005
  3.7261515e+013  2.8074611e+011  6.0529554e+010  4.6526109e+010  8.8187105e+009
  4.2891617e+008  3.3399747e+008  2.3567618e+008       5514656.2  1.0886563e+016
  5.0822256e+012  4.2606520e+012  3.4574549e+012  4.8146888e+012  2.1889083e+011
  5.9440783e+010  2.9261817e+011  2.7352748e+011  1.6880811e+010       5427422.1
 
       5.4480100       7815.7598       150050.67       661.04761
  6.1288988e+014  1.2700513e+017  5.8723511e+014  3.5728234e+010
  5.8294704e-005
  3.5683462e+013  2.5384893e+011  5.5923156e+010  4.3913848e+010  7.9879717e+009
  4.2221619e+008  3.5569163e+008  2.6120854e+008       6593980.5  1.0858113e+016
  6.5496220e+012  4.2756812e+012  3.4528678e+012  4.8045973e+012  2.1912650e+011
  5.9291026e+010  2.9183090e+011  2.7278652e+011  1.6835602e+010       16439751.
 
       5.6328301       8070.7402       155141.05       957.10530
  8.5934443e+014  1.2669695e+017  8.2976797e+014  4.5969175e+010
  5.3493306e-005
  3.4256800e+013  2.3384664e+011  5.2436476e+010  4.1924734e+010  7.3612337e+009
  4.1564742e+008  3.7379825e+008  2.8258736e+008       7579624.1  1.0852527e+016
  7.9545579e+012  4.2933534e+012  3.4545494e+012  4.8040922e+012  2.1963640e+011
  5.9266877e+010  2.9166248e+011  2.7262468e+011  1.6825953e+010       38973540.
 
       5.8130498       8273.6104       160104.71       1257.0857
  1.1010086e+015  1.2707348e+017  1.0890344e+015  5.5419273e+010
  5.0335003e-005
  3.3165940e+013  2.1951116e+011  4.9909152e+010  4.0488456e+010  6.9072045e+009
  4.1030501e+008  3.8870215e+008  2.9998290e+008       8432355.6  1.0906635e+016
  9.2558709e+012  4.3302601e+012  3.4745616e+012  4.8296892e+012  2.2122217e+011
  5.9569778e+010  2.9310359e+011  2.7396792e+011  1.6909027e+010       75510624.
 
       5.9957399       8470.2305       165136.41       1650.1675
  1.4117367e+015  1.2746898e+017  1.3741705e+015  6.7144588e+010
  4.7561693e-005
  3.2198577e+013  2.1096466e+011  4.8646866e+010  4.0037679e+010  6.6351079e+009
  4.1366258e+008  4.1223737e+008  3.2395283e+008       9519363.4  1.0964557e+016
  1.0448527e+013  4.3629694e+012  3.4945415e+012  4.8560044e+012  2.2270581e+011
  5.9884961e+010  2.9463872e+011  2.7540052e+011  1.6997785e+010  1.3657251e+008
 
       6.1877799       8638.8203       170425.63       2034.0333
  1.7061787e+015  1.2842183e+017  1.6973368e+015  7.7789634e+010
  4.5592899e-005
  3.1370412e+013  2.0234671e+011  4.7202329e+010  3.9335687e+010  6.3577137e+009
  4.1261545e+008  4.2944084e+008  3.4225967e+008       10439180.  1.1073148e+016
  1.1699058e+013  4.4168865e+012  3.5310770e+012  4.9051957e+012  2.2525455e+011
  6.0483192e+010  2.9754363e+011  2.7811293e+011  1.7165301e+010  2.2685785e+008
 
       6.3927798       8815.5400       176071.80       2562.0563
  2.1060112e+015  1.2932745e+017  2.0588835e+015  9.1917806e+010
  4.3645451e-005
  3.0607616e+013  1.9756938e+011  4.6676845e+010  3.9420155e+010  6.2012805e+009
  4.1958095e+008  4.5711511e+008  3.6924673e+008       11702654.  1.1180985e+016
  1.2881292e+013  4.4666488e+012  3.5664499e+012  4.9532641e+012  2.2766656e+011
  6.1069267e+010  3.0041780e+011  2.8079771e+011  1.7331306e+010  3.7094228e+008
 
       6.6154699       8973.2305       182205.20       3107.6001
  2.5095579e+015  1.3077666e+017  2.4576738e+015  1.0598644e+011
  4.2233113e-005
  3.0006219e+013  1.9353658e+011  4.6234729e+010  3.9519368e+010  6.0670881e+009
  4.2569238e+008  4.8310536e+008  3.9452068e+008       12931353.  1.1338250e+016
  1.4094380e+013  4.5362859e+012  3.6177123e+012  5.0233892e+012  2.3109021e+011
  6.1928024e+010  3.0462376e+011  2.8472717e+011  1.7574014e+010  5.7258811e+008
 
       6.8594999       9151.0098       188926.34       3794.8457
  3.0050107e+015  1.3204386e+017  3.0036080e+015  1.2208977e+011
  4.0628731e-005
  2.9122416e+013  1.8700403e+011  4.5222313e+010  3.9187209e+010  5.8516243e+009
  4.2734726e+008  5.0785678e+008  4.1937384e+008       14268147.  1.1492549e+016
  1.5578338e+013  4.6071855e+012  3.6685865e+012  5.0926213e+012  2.3453309e+011
  6.2774926e+010  3.0875113e+011  2.8858248e+011  1.7812014e+010  9.2589935e+008
 
       7.1298699       9320.0898       196372.95       4652.8611
  3.6176030e+015  1.3376423e+017  3.5522382e+015  1.4236905e+011
  3.9354527e-005
  2.8575971e+013  1.8554264e+011  4.5415852e+010  3.9882236e+010  5.7962606e+009
  4.3959640e+008  5.4593140e+008  4.5511527e+008       16033937.  1.1685642e+016
  1.6875828e+013  4.6891971e+012  3.7307910e+012  5.1781490e+012  2.3862731e+011
  6.3824578e+010  3.1390911e+011  2.9340244e+011  1.8109759e+010  1.4152869e+009
 
       7.4313698       9521.6797       204676.95       5749.4965
  4.3755954e+015  1.3507902e+017  4.3830810e+015  1.6508474e+011
  3.7728521e-005
  2.7529984e+013  1.7922965e+011  4.4480019e+010  3.9690818e+010  5.5846094e+009
  4.4252489e+008  5.7919648e+008  4.8769806e+008       17898863.  1.1868236e+016
  1.8632025e+013  4.7716807e+012  3.7907322e+012  5.2598752e+012  2.4265822e+011
  6.4825814e+010  3.1878938e+011  2.9796154e+011  1.8391120e+010  2.3465598e+009
 
       7.7694502       9739.6396       213988.46       7296.9920
  5.4290257e+015  1.3631797e+017  5.3444338e+015  1.9574080e+011
  3.6054499e-005
  2.6563923e+013  1.7592552e+011  4.4334612e+010  4.0267159e+010  5.4661709e+009
  4.5389318e+008  6.2893581e+008  5.3452200e+008       20487729.  1.2055483e+016
  2.0326398e+013  4.8530968e+012  3.8513869e+012  5.3429117e+012  2.4669326e+011
  6.5844204e+010  3.2377842e+011  3.0262344e+011  1.8678976e+010  3.8865873e+009
 

I would like to reformat the text in the file so it looks more tabular. The first row is the header, and the other rows are for the values. For example,

MassCol  T   Pg   Pe Ne  N_HI  N_HII  N_H-
0.0024755001       3854.1699       68.180943    0.0055848958  1.0500383e+010 1.1807884e+014       10675330.       5194.1882

Any suggestions?

Not at the moment. That does not really look like normal R output. What package or software produced it?

Hi @Cepheides,
Your data is pretty "messy" but does have a regular structure.
I was able to read the data from a txt file using this approach:

# Find the total lines in the txt file, hence the number of data "groups"
con <- file("testing_input.txt") 
in_len <- length(readLines(con, warn=FALSE))
groups <- (in_len-7)/8

# Pre-define data frame to contain output
out_df <- data.frame(row.names=1:groups)

# Read each group of data, make into one row
for(ii in 1:groups) {
  if (ii == 1) (skip_value = 7) else (skip_value = 7 + (ii-1)*8)
  
  dat <- read.table(file="testing_input.txt", skip=skip_value, 
                    header=FALSE, fill=TRUE, nrows=7)
  mat <- t(as.matrix(dat))

  wide_mat <- matrix(mat, nrow=1, ncol=35, byrow=TRUE)
  trim_mat <- matrix(wide_mat[, -c(5,10,12:15)], nrow=1, ncol=29, byrow=TRUE)
  out_df[ii, 1:29] <- as.data.frame(trim_mat)
  print(paste("DONE group", ii))
}

names(out_df) <- c("MassCol", "T", "Pg", "Pe",
                   "Ne",  "N_HI",  "N_HII",  "N_H-",
                   "N_H- / Ne",
                   "C_I", "Si_I", "Fe_I", "Mg_I", "Ni_I", 
                   "Cr_I", "Ca_I", "Na_I", "K_I", "He_I",
                   "C_II", "Si_II", "Fe_II", "Mg_II", "Ni_II", 
                   "Cr_II", "Ca_II", "Na_II", "K_II", "He_II")

out_df <- out_df[complete.cases(out_df), ]

head(out_df)

Not elegant but it gets the job done!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.