3

I need to read the file (contains 16K rows)and print the entire row if any of columns and all columns contains max value (100) and all columns contain min value (0).The ouput example is given

input.txt (tab-delimited)

Id sno1 sno2 sno3 sno4
E1 98   100  88   78
E2 33   99   78   66
E3 0     0   100  56
E4 0     0    0    0
E5 45   55   65   100
E6 0     0   99    88
E7 100 100  100   100

Ouput.txt

E1 98  100  88   78
E3 0    0   100   56
E4 0    0    0    0
E5 45   55   65   100
E7 100  100  100  100
1

2 Answers 2

3

Something like this [updated]?

perl -n -e 'if (/^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) { print if $1==100||$2==100||$3==100||$4==100||($1==0&&$2==0&&$3==0&&$4==0) }' input.txt

Will work with space separated columns too.

1
  • E3 is printed because sno3 row = 100. Aug 3, 2012 at 17:32
3

Also can be done in awk:

awk '$2 ~ /^0$/ && $3 ~ /^0$/ && $4 ~ /^0$/ && $5 ~ /^0$/ || /100/' $file

You must log in to answer this question.

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