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 want to read the file (1600 rows) and get rows only the columns have different values (sno1, sno2, sno3 & sno4-should be not be equal value) and it should be above 50%.The example of output given below

input.txt (tab-delimited)

id sno1 sno2 sno3 sno4
R1 98.4 88.8 98.4 67.6
R2 100  100  100  100
R3 33.4 23.5 98.8 45.5
R4 53.5 78.7 88.8 67.5
R5 0    0    0    0
R6 88.8 98.8 67.6 100

ouput.txt

R4 53.5 78.7 88.8 67.5
R6 88.8 98.8 67.6 100

Here in R4 & R6 rows- all column values have not equal to each other and all are above 50%. Any help in awk/sed/perl is appreciated.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

A perl-oneliner:

perl -nae 'undef %saw ; next if $. == 1; shift @F; next if grep { $_ < 50 or $saw{$_}++ } @F;  print ' input.txt

This basically translates to:

#!/usr/bin/env perl
use strict;

while (<>) {
  my @F = split(' ');  # split the current line
  my %seen;
  next if $. == 1;  # skip the heading
  shift @F;  # ignore first element

  next if grep { $_ < 50 or $seen{$_}++ } @F;  # ignore lines with
                                               # duplicate entries and
                                               # entries less than 50
  print;  # print current line
}
share|improve this answer

This might work for you (GNU sed):

sed '1d;/\S\+ \(\S\+\) .* \1/d;/\S\+ \S\+ \(\S\+\) .* \1/d;/\S\+ \S\+ \S\+ \(\S\+\) .* \1/d;/\S\+\( \(100\|[56789][0-9]\..\)\)\{4\}/!d' file
share|improve this answer
    
wow impressive, care to explain? –  Ulrich Dangel Aug 7 '12 at 20:04

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.