[Solved] Counting The Number of Lines Between Values with Multiple Variables

Hey everyone,

I have a bunch of lines with values in field 4 that I am interested in.

If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out

LOW and the number of lines with those values in between 1 and 3, so if there were 13 then it would be

LOW 13

Similarly, between values of 4 and 6 count the number of values and print out MEDIUM and the number of values, so if there were 50 then

MEDIUM 50

And again, between 7 and 10, HIGH and the number of lines, if there were 20 values

HIGH 20

I need all of these to happen together on one file and print out

LOW 13
MEDIUM 50
HIGH 20

I'm using awk to run these commands, but haven't really gotten anywhere. I know how to count patterns, but for some reason can't figure out what to do in this case.

Try something like:

awk '
  $4>0 && $4<4 {
    L++
  }
  $4>=4 && $4<7 {
    M++
  }
  $4>=7 && $4<=10 {
    H++
  }
  END{
    print "LOW",L+0 RS "MEDIUM", M+0 RS "HIGH",H+0
  }
' file
1 Like

Thank you, I was easily able to adapt this to my data and it works perfectly.