列の値と一致しない行データを取得する

列の値と一致しない行データを取得する

ファイル(1600行)を読み取って行を取得しようとしていますが、列の値だけが異なり(sno1、sno2、sno3、およびsno4 - 値と等しくないこと)、50%を超えてはいけません。下記の出力例

input.txt(タブ区切り)

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

出力.txt

R4 53.5 78.7 88.8 67.5
R6 88.8 98.8 67.6 100

R4行とR6行では、すべての列値が互いに等しくなく、50%を超えています。 awk/sed/perl のお手伝いをいただきありがとうございます。

ベストアンサー1

Perl-oneliner:

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

これは基本的に次のように解釈されます。

#!/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
}

おすすめ記事