awk '{ for (i=1;i<=NF;i++) if ( $i == "word" ) count++ } END{print count}' filename This will print the count of the occurance of a pattern "word" in a file.
If one would like to compare the values of 2nd column of consecutive lines of same file in such a way so that if the difference between first value and second value is more than 100 it should print complete line else ignore line.
Input File:
=======
ABC 2500
ABCD 123
XYZ 122
WXYZ 2565
Desired Output:
==========
ABC 2500 (i.e. difference between 2500 and 123 is greater than 100 here)
XYZ 122 (i.e. difference between 122 and 2565 is greater than 100 here)