我有一个很大的文件,像这样:
computer1 ram1.2 500
computer1 ram1.3 500
computer1 ram1.2 100
computer1 ram1.3 250
computer1 hdd0.1 205
computer2 ram1.2 400
computer2 ram1.3 2.3
computer2 ram6 12
computer2 hdd0.1 240
computer2 hdd0.1 223
computer2 ram6 120
我只需要grep来自第二列的第一个值,就像这样:
computer1 ram1.2 500
computer1 ram1.3 500
computer1 hdd0.1 205
computer2 ram1.2 400
computer2 ram1.3 2.3
computer2 ram6 12
computer2 hdd0.1 240
我尝试使用awk ! a[$2]++
,但对我来说不起作用。
答案 0 :(得分:0)
解决方案如下
awk '!seen[$1$2]++' file.ext
从此
$ cat file.ext
computer1 ram1.2 500
computer1 ram1.3 500
computer1 ram1.2 100
computer1 ram1.3 250
computer1 hdd0.1 205
computer2 ram1.2 400
computer2 ram1.3 2.3
computer2 ram6 12
computer2 hdd0.1 240
computer2 hdd0.1 223
computer2 ram6 120
您获得了
$ awk '!seen[$1$2]++' file.ext
computer1 ram1.2 500
computer1 ram1.3 500
computer1 hdd0.1 205
computer2 ram1.2 400
computer2 ram1.3 2.3
computer2 ram6 12
computer2 hdd0.1 240