Thursday, July 23, 2015

Filter lines that have sum above or below

Similarly to the previous post you can use awk code to print lines with the sum above or below a certain value.

Above 1000

awk '{for(i=1;i<=NF;i++) t+=$i; if(t>=1000) print$0; t=0}' file.txt> file_filtered.txt

Below 1000

awk '{for(i=1;i<=NF;i++) t+=$i; if(t<=1000) print$0; t=0}' file.txt> file_filtered.txt

No comments:

Post a Comment