使用awk删除筛选组
我有意见使用awk删除筛选组,awk,Awk,我有意见 1 a 0,9 1 b 0,8 1 c 0,1 2 d 0,5 3 e 0,1 3 f 0,7 4 g 0,4 4 h 0,3 4 i 0,2 4 j 0,1 使用awk我想删除已筛选的组 如果第三列大于0.6,我想删除第一列相等的其他行 期望输出: 2 d 0,5 4 g 0,4 4 h 0,3 4 i 0,2 4 j 0,1 我已经使用了这个,但它不会删除其他
1 a 0,9
1 b 0,8
1 c 0,1
2 d 0,5
3 e 0,1
3 f 0,7
4 g 0,4
4 h 0,3
4 i 0,2
4 j 0,1
使用awk我想删除已筛选的组
如果第三列大于0.6,我想删除第一列相等的其他行
期望输出:
2 d 0,5
4 g 0,4
4 h 0,3
4 i 0,2
4 j 0,1
我已经使用了这个,但它不会删除其他行
awk '($3 < 0.6)' file
awk'($3<0.6)文件
对于您展示的样品,请尝试以下内容
awk '
FNR==NR{
temp=$3
sub(/,/,".",temp)
if(temp>0.6){
noCount[$1]
}
next
}
!($1 in noCount)
' Input_file Input_file
输出如下
2 d 0,5
4 g 0,4
4 h 0,3
4 i 0,2
4 j 0,1
说明:添加上述内容的详细说明
awk ' ##Starting awk program from here.
FNR==NR{ ##This condition will be TRUE when first time is being read.
temp=$3 ##Creating temp with 3rd field value here.
sub(/,/,".",temp) ##Substituting comma with dot in temp here.
if(temp>0.6){ ##Checking condition if temp is greater than 0.6 then do following.
noCount[$1] ##Creating noCount with index of 1st field.
}
next ##next will skip all further statements from here.
}
!($1 in noCount) ##If 1st field is NOT present in noCount then print line.
' Input_file Input_file ##Mentioning Input_file names here.
谢谢你的更正。但我想在输出中看到“1 c 0,1”和“3 e 0,1”。@ersan,好的,请检查我的更新答案,并让我知道这是否对您有帮助,干杯。谢谢您的详细解释。虽然第3列中有一个不需要的值,但我想删除属于同一行第一列的其他数据。@ersan,请尝试我编辑的代码,并告诉我现在是否一切正常。@ersan,没有问题,我想我得到的是正确的,请检查我更新的代码,并告诉我它的运行情况,根据所示的样品,这工作正常。