Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter on column value in bash

I'm facing a problem while trying to grep (filter) a logfile on the value of an integer.

logfile.log:

2014-11-16 21:22:15 8 10.133.23.9 PROXIED ...
2014-11-16 21:22:15 1 163.104.40.133 authentication_failed DENIED ...
2014-11-16 21:22:15 15 163.104.40.134 authentication_failed DENIED ...
2014-11-16 21:22:16 9 163.104.124.209 PROXIED ...

I have an int in column 3 : 8, 1, 15, 9.

I need to grep only if: value > 10.

Something like:

cat logfile.log | grep {$2>10}
2014-11-16 21:22:15 15 163.104.40.134 authentication_failed DENIED ...
like image 849
B3luT Avatar asked Jan 09 '23 10:01

B3luT


1 Answers

This should make!

$ awk '$3>10' file
2014-11-16 21:22:15 15 163.104.40.134 authentication_failed DENIED ...

With $3 we refer to the 3rd field, so that $3>10 means: lines having 3rd field bigger than 10. If this is accomplished, the condition is true and hence awk performs its default behaviour: print the line.

You could of course say: print just an specific field, which you could by saying awk '$3>10 {print $1}' file, for example.

like image 82
fedorqui 'SO stop harming' Avatar answered Jan 16 '23 09:01

fedorqui 'SO stop harming'