Issue
I have a long file with 3 columns like this
2 189939871 21
2 189939872 21
2 189939873 19 ##########
2 189939874 19 ## Here there is one
2 189939875 18 ##########
2 189939876 23
2 189939877 30
2 189939878 15 ##########
2 189939879 15 ## Here there is the second one
2 189939880 24
2 189939881 12 ## The third one
2 189939882 30
2 189939883 10 ##########
2 189939883 10 ##########
2 189939883 10 ##########
2 189939883 10 ## the last one
2 189939883 10 ##########
I want to count the number of times there is gaps in the third column that are less than 20. (I have put comments on the right of the example to show you what I mean).
I have been thinking for a while but I don't even know how to do this. The desired results would be 4.
EDIT (For a better explanation.
For gaps I mean, each time there is a number or group of number than are less than 20. In the example above the first gap appear in the third line to the 5th line. That is a gap. Then the second gap in the example starts in the 8th to the 9th line. A gap can be also form by a single number that is less than 20. An example is given in the line 11. And the last gap is formed by 5 lines from the 13th line to the end
Solution
$ awk '$3<20&&(p>=20||p==""){c++}{p=$3}END{print c}' file
Output on your sample data:
4
Answered By - James Brown Answer Checked By - Katrina (WPSolving Volunteer)