AWK - 删除行如果字段是重复的 [英] awk - Remove line if field is duplicate
本文介绍了AWK - 删除行如果字段是重复的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
寻找一个awk(或SED)单行,从输出中删除行,如果第一个字段是重复的。
去除我见过重复行的一个例子是:
的awk'了〜$ 0!; {a = $ 0}
在使用它,没有运气的基础试过了(我以为改变$ 0 $ 1的会做的伎俩,但似乎不工作)。
解决方案
的awk'{如果(A [$ 1] ++ == 0)打印$ 0; }'$ @
这是一个标准的(很简单),用于关联数组。
Looking for an awk (or sed) one-liner to remove lines from the output if the first field is a duplicate.
An example for removing duplicate lines I've seen is:
awk 'a !~ $0; {a=$0}'
Tried using it for a basis with no luck (I thought changing the $0's to $1's would do the trick, but didn't seem to work).
解决方案
awk '{ if (a[$1]++ == 0) print $0; }' "$@"
This is a standard (very simple) use for associative arrays.
这篇关于AWK - 删除行如果字段是重复的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文