Scenario:
Each of several .txt files contain the following (but perhaps with some minor variations due to code version running on the devices from which the text was extracted):
<output omitted>
SWITCH1#show proc cpu hist
1 111111111111111 11111 11111 11111 11
3999995555511111333336666622222666661111144444111116666633
100
90
80
70
60
50
40
30
20 *****
10 ***************************************** ************
0....5....1....1....2....2....3....3....4....4....5....5....
0 5 0 5 0 5 0 5 0 5
CPU% per second (last 60 seconds)
1111111111111111111111111111111121111721111111111111671111
5384363853456143653472465347484512537703585444536337004347
100
90
80 *
70 * *
60 * **
50 * **
40 # **
30 # **
20 * * * ** ** ** * ** * * ** * *#* *** * * **# *
10 ##########################################################
0....5....1....1....2....2....3....3....4....4....5....5....
0 5 0 5 0 5 0 5 0 5
CPU% per minute (last 60 minutes)
* = maximum CPU% # = average CPU%
7222227227777287222375286232282222172272262687777227223226272272227226
0280027203063046112658409100100011990171091324474418151608247111003502
100
90
80 * * ** * * * * * * * *
70 * * **** ** * ** * * * * ***** * * * * *
60 * * **** ** ** ** * * * * ****** * * * * * *
50 * * **** ** ** ** * * * * ****** * * * * * *
40 * * **** ** *** ** * * * * ****** * * * * * *
30 * * * **** ** *** ** * * * * * ****** * *** * ** * ** *
20 **********************************************************************
10 ######################################################################
0....5....1....1....2....2....3....3....4....4....5....5....6....6....7.
0 5 0 5 0 5 0 5 0 5 0 5 0
CPU% per hour (last 72 hours)
* = maximum CPU% # = average CPU%
SWITCH1#show run
Building configuration...
<output omitted>
I wanted to parse the CPU section out of each file, so I tried something like this:
awk '/^100/,/^Building/' *.txt
Unfortunately, a line beginning with "100" occurs again not too far down in the file from the first occurrence. "Building" only occurs once and thus I get my first snippet and then most of the rest of the output following the second instance of my first string.
Ideally I would end on the second "average CPU%" (not sure why there aren't three) but that looked to be a challenge for me so I thought maybe I could live with just matching on a line beginning with "Building" to end the range, and then figure out a way to not print that line or the one preceding it. Not pretty but I was trying to break the problem down into manageable pieces. At the very least, can someone please explain how to match a range one time and then print nothing further from that individual file?
As always, many thanks!
(Note: I see that spacing didn't survive the pasting process but I think the intent is still clear.)