1

Very new to Perl here, and having some issues with reformatting a simple tab-delimited text file. I have data in the following sample format:

Current Format

My issue is that I need to have it formatted like so, for easier import and manipulation into Excel:

Goal Format

I've looked at reading the file line by line to reformat, however, there aren't any unique markers at the beginning of each section. I'm thinking I need to have it read say, lines 1-4, and then tell it to move lines 5-8 to the right of that. The problem is that I haven't figured out how to do that yet. I know this is a simple issue, but I'm having trouble finding the right words to describe it for a search. Any help would be great!

DATE            YEARS           FOPT            FWPT            FGPT            FOPR            FGPR            FPR             FOIP            FGIP        
                YEARS           STB             STB             MSCF            STB/DAY         MSCF/DAY        PSIA            STB             MSCF        
 01-JAN-2017            0              0               0               0               0               0        6115.914        83583.97        116465.9        
 02-JAN-2017     0.002738       11.00000        601.0318        15.32740        11000.00        15327.40        6113.142        83572.97        116450.6        
 01-FEB-2017     0.084873       341.0000        19152.75        475.1494        11000.00        15327.40        6031.021        83243.02        115990.8        
 01-MAR-2017     0.161533       649.0000        37292.66        904.3167        11000.00        15327.40        5956.524        82935.01        115561.6        
 01-APR-2017     0.246407       990.0000        58243.70        1379.466        11000.00        15327.40        5876.442        82593.99        115086.5        
 01-MAY-2017     0.328542       1320.000        79079.74        1839.288        11000.00        15327.40        5800.343        82263.99        114626.6        
 01-JUN-2017     0.413415       1661.000        101135.3        2314.438        11000.00        15327.40        5722.951        81923.01        114151.5        
 01-JUL-2017     0.495551       1991.000        122918.9        2774.260        11000.00        15327.40        5648.966        81593.01        113691.7        
 01-AUG-2017     0.580424       2332.000        145857.5        3249.409        11000.00        15327.40        5573.238        81252.01        113216.5        
 01-SEP-2017     0.665298       2673.000        169191.9        3724.558        11000.00        15327.40        5498.008        80911.01        112741.4        
 01-OCT-2017     0.747433       3003.000        192119.9        4184.380        11000.00        15327.40        5425.544        80581.02        112281.6        
 01-NOV-2017     0.832307       3344.000        216161.2        4659.529        11000.00        15327.40        5350.898        80240.03        111806.5        
 01-DEC-2017     0.914442       3674.000        239740.7        5119.352        11000.00        15327.40        5278.792        79910.03        111346.6        
 01-JAN-2018     0.999316       4015.000        264431.3        5594.501        11000.00        15327.40        5204.354        79569.03        110871.5        
 01-FEB-2018     1.084189       4356.000        289439.2        6069.650        11000.00        15327.40        5129.924        79228.04        110396.4        
 01-MAR-2018     1.160849       4664.000        312282.3        6498.817        11000.00        15327.37        5062.650        78920.04        109967.2        
 01-APR-2018     1.245722       5005.000        337896.2        6973.841        11000.00        15323.38        4988.142        78579.04        109492.2        
 01-MAY-2018     1.327858       5335.000        363235.5        7431.890        11000.00        15268.27        4916.500        78249.04        109034.1        
 01-JUN-2018     1.412731       5676.000        390436.5        7901.710        11000.00        15155.48        4843.414        77908.03        108564.3        
 01-JUL-2018     1.494866       6006.000        417998.2        8354.361        11000.00        15088.38        4773.151        77578.03        108111.6        
 01-AUG-2018     1.579740       6347.000        447697.2        8821.693        11000.00        15075.22        4702.125        77237.03        107644.3        
 01-SEP-2018     1.664613       6688.000        478313.0        9289.262        11000.00        15082.86        4634.229        76896.02        107176.7        
 01-OCT-2018     1.746749       7018.000        508719.2        9740.840        11000.00        15052.62        4571.810        76566.02        106725.1        
 01-NOV-2018     1.831622       7359.000        540988.8        10206.46        11000.00        15020.06        4511.004        76225.01        106259.5        
 01-DEC-2018     1.913758       7689.000        573010.3        10656.68        11000.00        15007.15        4455.262        75895.01        105809.3        
 01-JAN-2019     1.998631       8030.000        606992.3        11121.45        11000.00        14992.70        4401.024        75554.01        105344.5        
 01-FEB-2019     2.083504       8371.000        641948.6        11585.98        11000.00        14984.82        4349.885        75213.01        104880.0        
 01-MAR-2019     2.160164       8679.000        674396.6        12005.95        11000.00        14999.00        4306.338        74905.01        104460.0        
 01-APR-2019     2.245038       9020.000        711534.7        12472.28        11000.00        15042.73        4260.784        74564.01        103993.7        
 01-MAY-2019     2.327173       9350.000        748723.5        12926.13        11000.00        15128.47        4219.197        74234.01        103539.8        
 01-JUN-2019     2.412046       9691.000        788594.9        13399.80        11000.00        15279.53        4178.616        73893.01        103066.2        
 01-JUL-2019     2.494182       10021.00        828604.3        13864.18        11000.00        15479.50        4141.516        73563.01        102601.8        
 01-AUG-2019     2.579056       10362.00        871545.1        14352.02        11000.00        15736.85        4105.234        73222.02        102113.9        
 01-SEP-2019     2.663929       10703.00        916133.9        14849.75        11000.00        16055.69        4070.880        72881.02        101616.2        
 01-OCT-2019     2.746064       11033.00        960886.4        15342.65        11000.00        16430.03        4039.280        72551.02        101123.3        
 01-NOV-2019     2.830938       11374.00        1008906.        15866.13        11000.00        16886.49        4008.094        72210.02        100599.9        
 01-DEC-2019     2.913073       11704.00        1057105.        16387.50        11000.00        17379.03        3979.109        71880.02        100078.5        
 01-JAN-2020     2.997947       12045.00        1108823.        16944.17        11000.00        17957.03        3950.133        71539.02        99521.81        
 01-FEB-2020     3.082820       12386.00        1162527.        17521.07        11000.00        18609.75        3921.907        71198.02        98944.91        
 01-MAR-2020     3.162218       12705.00        1214570.        18080.01        11000.00        19273.78        3895.990        70879.02        98385.98        
 01-APR-2020     3.247091       13046.00        1272386.        18701.42        11000.00        20045.55        3868.502        70538.03        97764.57        
 01-MAY-2020     3.329226       13376.00        1330490.        19327.26        11000.00        20861.12        3841.818        70208.03        97138.73        
 01-JUN-2020     3.414100       13717.00        1392917.        20001.99        11000.00        21765.62        3813.719        69867.03        96464.01        
 01-JUL-2020     3.496235       14047.00        1455673.        20682.99        11000.00        22700.08        3785.762        69537.03        95783.01        
 01-AUG-2020     3.581109       14388.00        1523140.        21417.82        11000.00        23704.14        3755.854        69196.04        95048.19        
 01-SEP-2020     3.665982       14728.45        1593156.        22183.11        10982.29        24686.80        3724.873        68855.59        94282.90        
 01-OCT-2020     3.748118       15056.25        1663019.        22949.65        10926.60        25551.35        3693.925        68527.79        93516.37        
 01-NOV-2020     3.832991       15391.43        1736970.        23762.90        10812.30        26233.86        3661.145        68192.62        92703.12        
 01-DEC-2020     3.915127       15710.64        1809460.        24561.33        10640.33        26614.34        3628.994        67873.41        91904.70        
 01-JAN-2021     4.000000       16033.87        1885083.        25392.98        10426.67        26827.46        3595.533        67550.20        91073.05        
 01-FEB-2021     4.084873       16349.32        1960994.        26224.89        10175.95        26835.54        3562.091        67234.72        90241.12        
 01-MAR-2021     4.161533       16628.56        2029893.        26977.77        9972.877        26888.75        3531.852        66955.48        89488.23        
 01-APR-2021     4.246407       16929.99        2106415.        27807.48        9723.618        26764.77        3498.559        66654.05        88658.52        
 01-MAY-2021     4.328542       17213.58        2180354.        28601.85        9452.904        26479.18        3466.719        66370.46        87864.15        
 01-JUN-2021     4.413415       17497.78        2256434.        29410.77        9167.752        26094.13        3434.329        66086.24        87055.20        
 01-JUL-2021     4.495551       17765.01        2329750.        30182.55        8907.761        25725.89        3403.460        65819.00        86283.39        
 01-AUG-2021     4.580424       18032.82        2405005.        30966.76        8638.755        25297.12        3372.135        65551.18        85499.14        
 01-SEP-2021     4.665298       18292.97        2479825.        31738.92        8392.174        24908.24        3341.327        65291.03        84727.00        
 01-OCT-2021     4.747433       18538.09        2551866.        32475.83        8170.492        24563.67        3311.953        65045.89        83990.05        
 01-NOV-2021     4.832307       18784.75        2625954.        33227.18        7956.682        24237.34        3282.043        64799.22        83238.66        
 01-DEC-2021     4.914442       19017.61        2697346.        33945.43        7762.066        23941.38        3253.480        64566.34        82520.38        
 01-JAN-2022     4.999316       19252.35        2770808.        34678.90        7572.204        23660.49        3224.343        64331.61        81786.92        
 01-FEB-2022     5.084189       19481.50        2843976.        35404.35        7392.131        23401.59        3195.548        64102.44        81061.42        
 01-MAR-2022     5.160849       19684.14        2909827.        36053.44        7236.975        23181.83        3169.805        63899.79        80412.31        
 01-APR-2022     5.245722       19903.39        2982450.        36765.10        7072.589        22956.78        3141.603        63680.52        79700.62        
 01-MAY-2022     5.327857       20110.98        3052469.        37447.84        6919.914        22758.06        3114.568        63472.91        79017.84        
 01-JUN-2022     5.412731       20320.81        3124543.        38147.35        6768.508        22564.88        3086.888        63263.07        78318.29        
 01-JUL-2022     5.494866       20519.63        3194034.        38819.07        6627.315        22390.69        3060.327        63064.23        77646.52        
 01-AUG-2022     5.579740       20720.71        3265567.        39508.09        6486.450        22226.12        3033.104        62863.13        76957.45        
 01-SEP-2022     5.664613       20917.56        3336825.        40192.39        6350.217        22074.62        3006.091        62666.28        76273.15        
 01-OCT-2022     5.746749       21104.24        3405524.        40850.45        6222.399        21934.84        2980.133        62479.59        75615.07        
 01-NOV-2022     5.831622       21293.17        3476231.        41526.19        6094.632        21798.19        2953.498        62290.66        74939.34        
 01-DEC-2022     5.913758       21472.41        3544389.        42176.40        5974.562        21673.90        2927.886        62111.43        74289.13        
 01-JAN-2023     5.998631       21653.89        3614528.        42844.56        5854.217        21553.48        2901.587        61929.95        73620.98        
 01-FEB-2023     6.083505       21831.75        3684371.        43509.15        5737.413        21438.46        2875.450        61752.10        72956.40        
 01-MAR-2023     6.160164       21989.52        3747209.        44106.70        5634.736        21340.87        2851.968        61594.31        72358.83        
 01-APR-2023     6.245038       22160.77        3816470.        44765.12        5524.197        21239.28        2826.114        61423.05        71700.38        
 01-MAY-2023     6.327173       22323.37        3883202.        45399.50        5420.102        21146.31        2801.226        61260.44        71065.95        
 01-JUN-2023     6.412046       22488.15        3951834.        46052.21        5315.413        21055.13        2775.637        61095.64        70413.20        
 01-JUL-2023     6.494182       22644.65        4017942.        46681.34        5216.496        20970.99        2750.992        60939.13        69784.02        
 01-AUG-2023     6.579055       22803.27        4085914.        47328.90        5116.863        20889.10        2725.648        60780.51        69136.47        
 01-SEP-2023     6.663929       22958.88        4153538.        47974.04        5019.781        20810.89        2700.421        60624.89        68491.30        
 01-OCT-2023     6.746064       23106.72        4218645.        48596.20        4928.067        20738.50        2676.114        60477.05        67869.16        
 01-NOV-2023     6.830938       23256.62        4285554.        49236.91        4835.434        20668.34        2651.099        60327.14        67228.40        
 01-DEC-2023     6.913073       23399.05        4349950.        49854.96        4747.661        20601.36        2626.989        60184.71        66610.37        
 01-JAN-2024     6.997947       23543.49        4416106.        50491.52        4659.146        20534.46        2602.172        60040.27        65973.77        
 01-FEB-2024     7.082820       23685.24        4481867.        51126.05        4572.865        20468.70        2577.455        59898.50        65339.21        
 01-MAR-2024     7.162218       23815.57        4543030.        51717.87        4494.042        20407.46        2554.418        59768.16        64747.36        
 01-APR-2024     7.247091       23952.33        4607999.        52348.48        4411.715        20342.14        2529.892        59631.40        64116.77        
 01-MAY-2024     7.329226       24082.35        4670476.        52956.85        4333.859        20279.16        2506.248        59501.38        63508.37        
 01-JUN-2024     7.414100       24214.26        4734605.        53583.48        4255.169        20213.80        2481.915        59369.47        62881.75        
 01-JUL-2024     7.496235       24339.69        4796254.        54187.91        4180.820        20147.85        2458.463        59244.04        62277.29        
 01-AUG-2024     7.581109       24466.97        4859514.        54810.26        4105.856        20075.47        2434.336        59116.76        61654.96        
 01-SEP-2024     7.665982       24591.98        4922323.        55430.28        4032.603        20000.66        2410.316        58991.75        61034.94        
 01-OCT-2024     7.748118       24710.87        4982678.        56028.05        3963.209        19925.92        2387.173        58872.85        60437.14        
 01-NOV-2024     7.832991       24831.55        5044581.        56643.31        3892.922        19846.90        2363.376        58752.17        59821.89        
 01-DEC-2024     7.915127       24946.34        5104051.        57236.38        3826.302        19768.92        2340.457        58637.38        59228.83                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
DATE            FWIP            WOPR            WOPR            WOPR            WOPR            WOPR            WOPR            WOPR            WOPR        
                                PROD1           PROD2           PROD3           PROD4           PROD5           PROD6           PROD7           PROD8       
 01-JAN-2017     217100.9              0               0               0               0               0               0               0               0        
 02-JAN-2017     217100.4       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-FEB-2017     217081.9       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAR-2017     217063.7       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-APR-2017     217042.8       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAY-2017     217022.0       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUN-2017     216999.9       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUL-2017     216978.1       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-AUG-2017     216955.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-SEP-2017     216931.9       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-OCT-2017     216909.0       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-NOV-2017     216885.0       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-DEC-2017     216861.4       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JAN-2018     216836.7       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-FEB-2018     216811.7       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAR-2018     216788.9       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-APR-2018     216763.3       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAY-2018     216737.9       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUN-2018     216710.7       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUL-2018     216683.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-AUG-2018     216653.5       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-SEP-2018     216622.8       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-OCT-2018     216592.5       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-NOV-2018     216560.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-DEC-2018     216528.1       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JAN-2019     216494.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-FEB-2019     216459.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAR-2019     216426.8       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-APR-2019     216389.6       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAY-2019     216352.4       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUN-2019     216312.6       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUL-2019     216272.6       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-AUG-2019     216229.6       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-SEP-2019     216185.0       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-OCT-2019     216140.3       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-NOV-2019     216092.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-DEC-2019     216044.0       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JAN-2020     215992.3       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-FEB-2020     215938.6       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAR-2020     215886.6       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-APR-2020     215828.8       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-MAY-2020     215770.7       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUN-2020     215708.2       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-JUL-2020     215645.5       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-AUG-2020     215578.0       1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        1000.000        
 01-SEP-2020     215508.0       1000.000        1000.000        1000.000        1000.000        982.2889        1000.000        1000.000        1000.000        
 01-OCT-2020     215438.1       1000.000        1000.000        1000.000        987.8972        938.7014        1000.000        1000.000        1000.000        
 01-NOV-2020     215364.2       1000.000        1000.000        1000.000        944.6985        898.9819        993.3375        975.2858        1000.000        
 01-DEC-2020     215291.7       1000.000        1000.000        987.2924        908.1062        864.7061        949.7439        930.4863        1000.000        
 01-JAN-2021     215216.1       1000.000        1000.000        943.4799        873.7346        832.9124        912.0916        890.2245        997.2469        
 01-FEB-2021     215140.2       1000.000        1000.000        904.1622        842.4350        804.3555        879.0031        854.7082        956.0581        
 01-MAR-2021     215071.3       1000.000        1000.000        870.7736        816.3723        780.9267        852.0299        825.9931        924.7631        
 01-APR-2021     214994.8       954.7792        1000.000        836.0588        789.7103        757.3873        824.8868        797.7160        894.4819        
 01-MAY-2021     214920.8       911.0792        975.8620        804.8063        765.7391        736.3005        800.6694        773.0909        868.2468        
 01-JUN-2021     214844.8       871.5847        937.1240        775.2373        742.5759        716.0410        777.5660        749.9798        843.6501        
 01-JUL-2021     214771.4       837.2768        904.5201        749.1047        721.7236        697.7020        756.6818        729.3855        821.6621        
 01-AUG-2021     214696.2       805.1511        874.2014        724.3899        701.5703        679.8192        736.4651        709.6801        800.4880        
 01-SEP-2021     214621.4       775.9127        846.4084        701.6760        682.5485        662.8802        717.3998        691.2787        780.7114        
 01-OCT-2021     214549.3       749.7907        821.4545        681.2459        665.1164        647.3070        699.8309        674.5302        762.7043        
 01-NOV-2021     214475.2       724.7822        797.2998        661.5366        648.1502        632.0221        682.5051        658.1393        745.2293        
 01-DEC-2021     214403.9       702.2817        775.4427        643.6191        632.6422        617.8698        666.4878        643.0541        729.3002        
 01-JAN-2022     214330.4       680.4999        754.2415        626.3231        617.6350        603.8210        650.6306        628.1135        713.7378        
 01-FEB-2022     214257.2       659.8911        734.3206        610.0309        603.4741        590.4399        635.4551        613.7855        698.9329        
 01-MAR-2022     214191.4       642.2538        717.2426        596.0644        591.3438        578.7999        622.2927        601.3787        686.1025        
 01-APR-2022     214118.8       623.9185        699.1006        581.3417        578.5496        566.3484        608.2764        588.2858        672.5278        
 01-MAY-2022     214048.7       607.1064        682.3412        567.8176        566.6968        554.7045        595.2209        576.1414        660.0051        
 01-JUN-2022     213976.7       590.6409        665.6839        554.4908        554.8932        543.1304        582.4323        564.1412        647.6615        
 01-JUL-2022     213907.2       575.4573        650.1886        542.1431        543.8680        532.2566        570.5046        552.9880        636.2126        
 01-AUG-2022     213835.6       560.4908        634.7764        529.9006        532.8980        521.3388        558.5575        541.8364        624.8486        
 01-SEP-2022     213764.4       546.1125        619.8396        518.0843        522.3292        510.7354        546.9831        531.0200        613.9029        
 01-OCT-2022     213695.7       532.6774        605.8235        507.0684        512.4412        500.7822        536.1215        520.8680        603.6258        
 01-NOV-2022     213625.0       519.3000        591.8784        496.1144        502.6051        490.8404        525.2750        510.7014        593.3254        
 01-DEC-2022     213556.8       506.7961        578.8516        485.8417        493.3380        481.4926        515.1389        501.1455        583.6576        
 01-JAN-2023     213486.7       494.4056        565.7899        475.5480        484.0696        472.1001        505.0061        491.5585        574.0311        
 01-FEB-2023     213416.8       482.5743        553.1757        465.5555        475.0787        462.9993        495.1956        482.2538        564.6810        
 01-MAR-2023     213354.0       472.3383        542.1322        456.7924        467.1158        454.9959        486.5961        474.0770        556.4614        
 01-APR-2023     213284.7       461.4807        530.2675        447.3766        458.4506        446.3148        477.3195        465.2596        547.6060        
 01-MAY-2023     213218.0       451.3690        519.0997        438.5150        450.2431        438.0808        468.5681        456.9575        539.2471        
 01-JUN-2023     213149.4       441.2621        507.8943        429.6058        441.9771        429.7339        459.8121        448.6269        530.8021        
 01-JUL-2023     213083.3       431.7662        497.3611        421.2060        434.1180        421.8166        451.5902        440.7804        522.8068        
 01-AUG-2023     213015.3       422.2752        486.8068        412.7331        426.1255        413.8506        443.2768        432.8996        514.7522        
 01-SEP-2023     212947.7       413.1162        476.5677        404.4641        418.2681        406.1547        435.1566        425.2336        506.8900        
 01-OCT-2023     212882.6       404.5550        466.9713        396.6953        410.8031        398.8955        427.4897        417.9343        499.4341        
 01-NOV-2023     212815.7       395.9970        457.3140        388.8615        403.2310        391.5630        419.7724        410.5210        491.8303        
 01-DEC-2023     212751.3       387.9415        448.2274        381.4816        396.0516        384.6046        412.4950        403.4929        484.5848        
 01-JAN-2024     212685.1       379.8392        439.1288        374.0844        388.7751        377.5343        405.2380        396.4141        477.2164        
 01-FEB-2024     212619.3       372.0302        430.2736        366.9381        381.6602        370.5826        398.1076        389.5168        469.9796        
 01-MAR-2024     212558.2       364.9457        422.1958        360.4506        375.1520        364.2364        391.5271        383.2607        463.3111        
 01-APR-2024     212493.2       357.5526        413.7945        353.6817        368.3677        357.6051        384.6405        376.6964        456.3391        
 01-MAY-2024     212430.7       350.6023        405.8729        347.2823        361.9444        351.3568        378.1276        370.4241        449.7133        
 01-JUN-2024     212366.6       343.5552        397.8953        340.8221        355.4449        345.0422        371.5763        364.0950        442.9857        
 01-JUL-2024     212305.0       336.8311        390.4166        334.7315        349.2879        339.0654        365.4244        358.1319        436.5724        
 01-AUG-2024     212241.7       330.1288        382.9009        328.5627        343.0389        333.0261        359.2823        352.1263        430.0231        
 01-SEP-2024     212178.9       323.6319        375.5858        322.5305        336.8866        327.1149        353.2987        346.2789        423.5484        
 01-OCT-2024     212118.5       317.5024        368.7001        316.8279        331.0237        321.5117        347.6066        340.7570        417.3516        
 01-NOV-2024     212056.6       311.2931        361.7720        311.0582        325.0747        315.8384        341.8568        335.1705        411.0209        
 01-DEC-2024     211997.2       305.4827        355.2180        305.6007        319.4813        310.4489        336.3815        329.8847        404.9657        
4
  • can you add more detail on your input file? does it have only those two blocks? are they always 3 lines and new line between them, etc... for given sample, grep '.' input_file | pr -2ts will work...
    – Sundeep
    Apr 29, 2017 at 2:31
  • @Sundeep I was able to add a sample of the actual data file. Some info about it: the width is always 10 tab delimited columns, their length is always two rows of headers followed by 97 rows of data. What changes is number of "row blocks". For example, I included 2 row blocks above, but the total number from the actual file is 12. Changes I will be making to the file will add additional blocks of rows. Let me know if that helps you understand a little better!
    – Shevinski
    Apr 30, 2017 at 17:03
  • Noticing a few errors in my last comment, I meant to say "column blocks" instead of "row blocks". A "column block" starts at each row of headers. I need to move the columns from the second, third, fourth, etc... blocks adjacent to the first with the two rows of headers lined up.
    – Shevinski
    Apr 30, 2017 at 18:02
  • instead of such long input, make a new sample with 2 or more header rows and few rows of data... either way, if you know that there are 12 such tables, simply use pr -12ts input_file
    – Sundeep
    May 1, 2017 at 2:07

2 Answers 2

1
perl -alF\\n -00ne '
   push @{ $A[$_] }, $F[$_] for 0 .. $#F; END{
   print join "\t", @$_ for @A;}
' yourfile.txt

  • Perl options

    -a For every record read in, it'll autosplit the record on the field separator given in the -F option and store the fields in the array @F.

    -l Sets ORS = RS = "\n"

    -F\\n Sets FS = "\n"

    -00 Sets RS = "\0" meaning, turn on the paragraph-mode. Note it overturns the RS from a prior setting via -l.

    -n Sets up an implicit file read in loop + donot print unless asked to.

    -e Apply the given Perl code on every record from input file.

  • Working

    @A is a list-of-list aka, an LoL, wherein we store the corresponding rows from every record. So, the first rows of every record is stored in $A[0], the second rows from every record go into $A[1], ...

    Then when have exhausted reading in all records from the file, we simply print out the array whose elements are an LoL , suitably joined together by TAB.

Results

HEADER1  HEADER2  HEADER3  HEADER4
item1    item1    item1    item1
item2    item2    item2    item2
0

I'm not sure that what you said you want is what you really want. I note that every block has Date as the first column and that, in your example, the values in that column are then same in every block. If what you really want in the output is each date followed by all the non-Date rows for that date in every block:

Date           Years …    FWIP
01-Jan-2017      0      217100.9

Then just use Perl to spit your data up into separate files ( a new file every time you see some lines that don't match the \d+\-…\-\d\d\d\d regex pattern of VMS date formats) and use the shell command join to do the rest as per this post on exactly this problem

Don't write code when there's already a tool to do your specialized, yet very common, problem!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .