Skip to content
Advertisement

How do I find the number of elements in a column greater than a given number in Linux?

I have a text file of list of students with Marks and I want to find how many of them secured more than 80 in Maths, Physics and then Maths and Physics combined. What should be the Linux command to do this?

The text file is here:

#name maths phy
Manila 78 29
Shikhar 49 78
Vandana 65 87
Priyansh 75 22
Bina 52 69
Chitransh 98 93
William 88 73
Kaushal 38 85
Dilruba 65 94
Lalremruata 34 45
Qasim 58 62
Nitya 81 89
Jennita 96 91
Shobha 71 63
Talim 77 88 

Advertisement

Answer

This can be achieved using awk (don’t use grep because this is not fit for number arithmetic). An example:

cat test.txt | awk '{if ($2>80 || $3>80) print $1 " " $2 " " $3}'

This needs to be improved: how to remove the cat command, how to check the sum of both columns, why is the title present, …? But at least you have something to start.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement