Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
can you use python? –  undefined is not a function Aug 3 '12 at 17:17
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
E3 is printed because sno3 row = 100. –  Tim Kennedy Aug 3 '12 at 17:32
add comment

Also can be done in awk:

awk '$2 ~ /^0$/ && $3 ~ /^0$/ && $4 ~ /^0$/ && $5 ~ /^0$/ || /100/' $file
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.