I have a file with the below data in test1.txt:

nnn   90
vvv   80
ttt   50
sss   20

I want to compare the second column value and remove that line. For example, if any of the second column value is less than 20, then delete that line entry. The output of test1.txt should look like:

nnn   90
vvv   80
ttt   50

I tried with sed and awk commands, but it's not working for me.

  • What commands did you try that didn't work? Also, I assume you meant less than or equal to 20, right?
    – terdon
    Oct 12, 2015 at 13:44

2 Answers 2


With awk:

awk '$2>20' file

It checks if the second field $2 in geather than 20. If yes, the line is printed.


With bash:

$ while read -r a b; do [ "$b" -gt 20 ] && echo "$a $b"; done <file.txt 
nnn 90
vvv 80
ttt 50

This will read each line and check if the value of second column of the space separated columns is greater than 20, if so it will print the line.

  • thanks ..but i need to write this output to a file
    – user138139
    Oct 14, 2015 at 6:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .