An efficient way to count the number of rows that obey a certain condition

I am trying to count the number of lines in a file, which is the 4th field greater than the first filed using the awk command. I came up with this command:

awk '$4>$1 {print}' sampleFile | wc -l 

Is there a better way to find a number and not use wc -l

+6
source share
1 answer

One way: GNU awk :

 awk '$4 > $1 { count++ } END { print count }' file.txt 
+13
source

Source: https://habr.com/ru/post/927303/


All Articles