iterate through list of numbers and print specific lines with awk

Could someone please point me in the right direction with the following?

I have a program that generates logs that contains sections like this:

 IMAGE INPUT
     81   0  0.995  2449470    0   1726     368     1  0.0635  0.3291
     82   0  1.001  2448013    0   1666     365     1  0.0649  0.3235
     83   0  1.009  2444822    0   1697     371     1  0.0661  0.2888
     84   0  1.004  2447224    0   1733     362     1  0.0664  0.3346
     85   0  1.011  2446792    0   1704     357     1  0.0665  0.3024
     86   0  1.016  2450130    0   1675     362     1  0.0660  0.3208
     87   0  1.018  2448809    0   1719     349     2  0.0669  0.2914
     88   0  1.017  2448947    0   1710     357     2  0.0677  0.3044
     89   0  1.028  2447439    0   1721     368     2  0.0643  0.3164

  ACCEPTED

What I would like to do is produce an awk (or sed) one-liner that would
search between regular expression /IMAGE/ and /ACCEPTED and produce the following output:

 processing images 81 - 89 

Where 81 and 89 are first fields of the first and last number-containing lines respectively. These numbers can be any range between "IMAGE" and "ACCEPTED", but are always consecutive and increment by 1.

Parsing first and last lines that only contain numbers in awk without multiple pipes has got me stuck.

Thanks!

you can use the below command:--

awk '{print "processing images"$1}' ur_file

but this will give you all the numbers in 1 straight line....

One way.

awk '/ACCEPTED/{print "processing images "x" - "y;exit}/IMAGE/{getline;x=$1}NF{y=$1}'  file
1 Like

Thanks danmero!

---------- Post updated at 12:25 PM ---------- Previous update was at 11:43 AM ----------

So, I've almost got my little script running, but seem stuck again at printing out averages of columns.

What I have in my script is this:

program | tee $log | awk '\
/ACCEPTED/ {
    print "processing images "x" - " y}
/IMAGE/ {
    f=1;getline;x=$1} NF {y=$1}
{tot += $7; ++n} 
END { printf "average count is %3d\n", tot/n}
'

And what I would like to have is:

 processing images 1 - 9 average count is 362 

where 362 is the average in column 7, for that section of the log (see below in my original post).

What I get with my script is this:

processing images 1 - 9
processing images 10 - 18
processing images 19 - 27
processing images 28 - 36
processing images 37 - 44
processing images 45 - 52
processing images 53 - 60
processing images 61 - 68
processing images 69 - 76
processing images 77 - 84
The average count is 4087

Thanks in advance.

awk '/ACCEPTED/{print "processing images "x" - "y" Average is "int(tot/nb)}/IMAGE/{getline;tot=nb=0;x=$1}$7>0{tot+=$7;nb++}NF{y=$1}' file
1 Like