count lines with different conditions using awk

I need to get the number of lines with 2 different conditions for 1 text file.
The first condition is that values of the third column are smaller than 10 so I can do it by the following script:

awk '$3<=10' DATA_File | wc -l

The second condition is just to get a total number of lines in the same file this I can get by:

awk 'END { print FNR}' DATA_File

or

awk '$3' DATA_File | wc -l

However, what I don’t know is how to merge these to commands in a single string so I can get the result saved in a separate file with one string separated by either “tab” or “space” consisting of “number of string with <10”, “total number of strings”, “their ratio/ or percentage”

for instance the file is:

wer fre 11
grt o34 5
45f 123 45

the output I need is:

2 3 0.66/ or 66%

I could write a small script on python which would do it but due to a number of reasons bash would be much more convenient.


Source: bash

Leave a Reply