My file looks like this:
AA 110 B 10 .. BB 15 ... BBB 20 D F 25 D D
AA 111 B 50 .. BB 55 ... BBB 30 F F 45 F F
AA 112 C 2 .. BB 3 ... BBB 0 D F 0 D F
AA 120 D 2 .. FF 3 ... FFF 3 D F 3 D D
I would like to delete lines containing a value =< 10 in any of the columns. I am aware of the use of sed
and awk '$3 !=< 10'
but this would only delete lines at the third field. Is there a way to tell qwk to consider all columns?
Best Answer
perl
to the rescue-a
split input line on space and save to@F
arraygrep { $_ <= 10 && /^\d+$/ } @F
get all elements of@F
array which are made of only digits and whose value is<= 10
0
. The()
aroundgrep
means it will return count of matches rather than elements themselvesLet's test another condition:
Certain conditions, like in this question, can be solved with
grep
too (which probably is faster thanperl
solution)-v
lines other than matching pattern-w
match whole words only