I recently needed to filter some log data to find all the entries that exceeded a certain numeric value (in my case, 100). A little Googling yielded the following solution:
less /web/temp/apache_procs.log | awk '{ if( $6 >= 100) print $1 " " $2 " " $6}'
The first half of this command obviously opens the file in the ‘less’ viewer. The ‘awk‘ command, if you’re not familiar with it, is an excellent tool for printing various bits of tab-separated files. One of the things it does is automatically separate each column of the log file output into a numeric variable, so the first column is $1, the second is $2, and so on. In this case, I wanted to see columns 1, 2, and 6 (log date, log time, and number of apache processes running). Awk also allows for simple if statements, in this case ‘if ($6 >= 100)’, a simple check that results in awk printing out only the log entries where the numeric value of column 6 is greater than (or equal to) 100.