Solved extract lines from file with value in column within range

July 7, 2012 at 15:20:49
Specs: Linux i686
I need help in finding a way to extract lines from a file with tab delimited columns in Linux.
I need to extract lines which have a value in column 3 that falls within range 35-51 as in the example. Thanks.

Example:
abcd fjgu 17 1948 X2644
sdfg dkri 36 1934 X3498
werd dkic 28 1834 X0932
werd edcv 55 1873 X2742
werf edcv 12 1932 X2341
qasd qwsx 50 1823 X9992
edcf edss 98 1932 X2381
edhy edyh 44 1934 X3399

Needed result:
sdfg dkri 36 1934 X3498
qasd qwsx 50 1823 X9992
edhy edyh 44 1934 X3399


See More: extract lines from file with value in column within range

Report •

#1
July 8, 2012 at 15:15:08
✔ Best Answer
Use awk:

awk '$3 >= 35 && $3 <=51 {print $0}' yourfile

Tony


Report •

#2
July 9, 2012 at 08:07:23
It works like a charm.
Thanks a lot, Tony.

Report •

#3
July 9, 2012 at 22:18:07
awk works and so does perl:

# perl arrays start counting from zero
perl -wnla -e '
if($F[2] >= 35 && $F[2] <= 51)
   {
   print "@F";
   }
' yourfile


Report •
Related Solutions


Ask Question