我有一个输入
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
Run Code Online (Sandbox Code Playgroud)
使用awk,如果第三列大于0.6,我想删除过滤组,我想删除第一列相等的其他行。
期望输出:
2 d 0,5
4 g 0,4
4 h 0,3
4 i 0,2
4 j 0,1
Run Code Online (Sandbox Code Playgroud)
我用过这个,但这不会删除其他行。
awk '($3 < 0.6)' file
Run Code Online (Sandbox Code Playgroud)
使用您显示的样本,您能否尝试以下操作。
awk '
FNR==NR{
temp=$3
sub(/,/,".",temp)
if(temp>0.6){
noCount[$1]
}
next
}
!($1 in noCount)
' Input_file Input_file
Run Code Online (Sandbox Code Playgroud)
输出如下。
2 d 0,5
4 g 0,4
4 h 0,3
4 i 0,2
4 j 0,1
Run Code Online (Sandbox Code Playgroud)
说明:为以上添加详细说明。
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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |