Awk打印列的最大值大于0.5的特定行

Awk打印列的最大值大于0.5的特定行,awk,Awk,我有一个以制表符分隔的文件,看起来像这样,有5列 temp1 56 09 34,54,65,6 file1 temp2 45 23 4,55,11,7,8,4,7 file2 temp3 123 56 0.01,0,50,4,4,4,6,7,1,3,44,67,8 file3 temp4 11 56 0.006,0.006,0.006 file4 temp5 10 123 0.00001,0.005,0.004 file5 我

我有一个以制表符分隔的文件,看起来像这样,有5列

temp1   56   09   34,54,65,6   file1
temp2   45   23   4,55,11,7,8,4,7   file2
temp3   123  56   0.01,0,50,4,4,4,6,7,1,3,44,67,8  file3
temp4   11   56   0.006,0.006,0.006  file4
temp5   10   123  0.00001,0.005,0.004 file5
我希望能够拆分第4列,并查看列表中的每个值,如果第4列中该列表的最大值大于0.5,则打印出整行

因此,输出将是:

temp1   56   09   34,54,65,6   file1
temp2   45   23   4,55,11,7,8,4,7   file2
temp3   123  56   0.01,0,50,4,4,4,6,7,1,3,44,67,8  file3
这就是我迄今为止所做的尝试:

cat inputFile.txt|awk 'BEGIN {FS="\t"}; NR>1 {print $4}'|awk '{split($1,a,","); if (max(a)>0.5) print $0}'

但是我开始感到困惑了。

你能试试下面的内容吗

awk '
{
  num=split($4,array,",")
  for(i=1;i<=num;i++){
    max=max>array[i]?max:array[i]
  }
  if(max>0.5){
    print
  }
  max=""
}
' Input_file

你好第4列中的所有值都需要它,所以有些行有10个逗号分隔的值,其他行有3个,其他行可以有2个。我需要列表中的最大值。@Rk\U 23,好的,当然,请检查我的更新,然后让我知道。无需使用
FS=“\t”
。任何空格/制表符都是
awk
的默认行为,因此,如果其空格、多个空格或制表符为空,则第一个解决方案将起作用。@RavinderSingh13谢谢您的帮助。这个解决方案引导我们进入正确的方向,并回答了我的问题!谢谢你!
awk '                                   ##Starting awk program here.
{
  num=split($4,array,",")               ##Splitting 4th column into an array named array with delimiter of comma here.
  for(i=1;i<=num;i++){                  ##Starting a for loop from i=1 till value of num(which is total number of elements after we split 4th column with delimiter comma).
    max=max>array[i]?max:array[i]       ##Creating a variable named max whose value is max or array with index i whichever is greater each time cursor comes here.
  }
  if(max>0.5){                          ##Checking condition here if max variable is grater than 0.5 as per OP need then do following.
    print                               ##Printing current line.
  }
  max=""                                ##Nullifying max variable value so that next cycle it should not take previous values.
}
' Input_file                            ##Mentioning Input_file name here.
$ cat tst.awk
BEGIN { FS="\t"; tgt=0.5 }
{
    split($4,vals,/,/)
    max = vals[1]
    for (i in vals) {
        max = (vals[i] > max ? vals[i] : max)
    }
}
max > tgt

$ awk -f tst.awk file
temp1   56      09      34,54,65,6      file1
temp2   45      23      4,55,11,7,8,4,7 file2
temp3   123     56      0.01,0,50,4,4,4,6,7,1,3,44,67,8 file3