Menu

Help extracting lines from text files

Help
bkmunger
2010-10-15
2012-07-26
  • bkmunger

    bkmunger - 2010-10-15

    I am trying to use gawk to extract a set of lines from a text file. The limes
    start with a certain identifier but are not always at the same line numbers in
    the file. An example is below. I want to find the identifier "REPORT- PS-E"
    and then extract the set of 5 lines starting with the 13th occurance of the
    string "KWH". I have to do this frequently so I am trying to set up a batch
    file to do this. I have used gawk before but my code writing skills are very
    rusty. Can anyone help?

    Thanks, Bryce

    ---- start of identifier -------
    REPORT- PS-E Energy End-Use Summary for all Electric Meters WEATHER FILE-
    PORTLAND INTERNAT OR


    TASK MISC SPACE SPACE HEAT PUMPS VENT REFRIG HT PUMP DOMEST EXT

    LIGHTS LIGHTS EQUIP HEATING COOLING REJECT & AUX FANS DISPLAY SUPPLEM HOT WTR
    USAGE TOTAL


    JAN

    KWH 75964. 0. 15908. 41390. 2976. 0. 566. 42293. 0. 2162. 0. 0. 181257.

    MAX KW 166.020 0.000 61.777 212.826 39.967 0.000 1.600 89.701 0.000 21.767
    0.000 0.000 499.692

    DAY/HR 1/ 8 0/ 0 4/12 4/ 6 20/16 0/ 0 4/21 1/ 8 0/ 0 1/ 8 0/ 0 0/ 0 4/ 6

    PEAK ENDUSE 166.020 0.000 11.812 212.826 0.000 0.000 0.077 89.701 0.000 19.255
    0.000 0.000

    PEAK PCT 33.2 0.0 2.4 42.6 0.0 0.0 0.0 18.0 0.0 3.9 0.0 0.0

    -------- skip lines for post length -------
    -------- want to extract --------
    KWH 906775. 0. 195025. 163578. 232611. 0. 3826. 465954. 0. 6672. 0. 0.
    1974442.

    MAX KW 166.020 0.000 61.777 212.826 335.375 0.000 1.600 89.701 0.000 21.767
    0.000 0.000 629.360

    MON/DY 1/ 1 0/ 0 1/ 4 1/ 4 7/21 0/ 0 1/ 4 1/ 1 0/ 0 1/ 1 0/ 0 0/ 0 7/21

    PEAK ENDUSE 166.020 0.000 38.264 0.000 335.375 0.000 0.000 89.701 0.000 0.000
    0.000 0.000

    PEAK PCT 26.4 0.0 6.1 0.0 53.3 0.0 0.0 14.3 0.0 0.0 0.0 0.0

    ---------- end of extract -----------

     
  • Charles Calvert

    Charles Calvert - 2010-10-15

    This is a question about gawk in general, rather that the GnuWin32 port of it.
    You'd be better off asking this in the comp.lang.awk newsgroup. If you're not
    familiar with Usenet, you can access it via Google
    Groups
    .

     
  • Charles Calvert

    Charles Calvert - 2010-10-15

    This is a question about gawk in general, rather that the GnuWin32 port of it.
    You'd be better off asking this in the comp.lang.awk newsgroup. If you're not
    familiar with Usenet, you can access it via Google
    Groups
    .

     
MongoDB Logo MongoDB