gawk '{if(a[$3]=="") a[$3]=$0;else if(a[$3]!=""&&b[$3]=="") {b[$3]++;printf("%s\n%s\n", a[$3],$0);} else print $0}' file
[root@localhost test]# cat file
1 2 3 4
a b c d
d d 3 c
e b m d
5 7 c f
[root@localhost test]# awk '{if(a[$3]=="") a[$3]=$0;else if(a[$3]!=""&&b[$3]=="") {b[$3]++;printf("%s\n%s\n", a[$3],$0);} else print $0}' file
1 2 3 4
d d 3 c
a b c d
5 7 c f
[root@localhost test]#
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27181165/viewspace-1322927/,如需转载,请注明出处,否则将追究法律责任。