[英]How to delete duplicated rows on one file based on a common field between two files with AWK?
[英]How to print non duplicated rows based on a field with AWK?
我希望使用AWK根据第一个字段打印非重复行。 谁能帮忙吗?
谢谢
Input
1 28324 2077 2 1
1 24682 2088 1 0
1 25399 2074 1 0
2 28925 1582 2 1
3 30254 1450 1 0
4 25552 1131 1 1
4 31033 1134 1 0
5 29230 1522 2 0
Desired Output
2 28925 1582 2 1
3 30254 1450 1 0
5 29230 1522 2 0
awk '
(count[$1]++ < 1) { data[$1] = $0; }
END { for (x in data) if (count[x] == 1) print data[x]; }
'
如果输出应在第一列上sort -nk1
,请通过sort -nk1
其通过管道sort -nk1
。
如果您的数据已排序,则可以使用此方法,它不会累积潜在的大数组。
awk '
$1 != prev { if (count == 1) print line; count = 0 }
{ prev=$1; line = $0; ++count }
END { if (count == 1) print }' inputfile
对于第一列和支持-w选项的uniq实现中固定数量的字符:
sort infile|uniq -uw1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.