轉載:http://blog.csdn.net/challenge_c_plusplus/article/details/23053573數組
一條命令搞定:ide
awk '!a[$0]++' filespa
若是是第一次出現a[$0]++的值爲0(假),而!a[$0]++的值就爲1(真),以後就執行print $0.net
第二次或者兩次以上的出現a[$0]++的值就爲大於0的整數值(真),例如1,2,3...,而!a[$0]++的值就爲0(假),以後就不執行print $0操做orm
awk '!($0 in a){a[$0];print $0}'blog
pattern爲!($0 in a),Action爲{a[$0];print $0}it
分析:io
1.執行第一行時的a的數組爲空,($0 in a)爲假,!($0 in a)爲真。執行Action,a[$0]就存在了a[row1],打印第一行class
2.執行第二行時的a的數組爲a[row1],若是a[row2] 是a[$0]中的元素,!($0 in a)爲真爲假,不執行Ation。若是a[row2]不是a[$0]中的元素,執行Action,a[$0]中增長元素(a[row1],a[row2]),打印第二行。awk
3.重複執行相似的第二步驟。達到的去重的效果。