Printing first four lines per key
I would like to print the first 4 lines by field 1 using awk
Input
111 1032192
111 2323476 111 1698881 111 2451712 111 2013780 112 2331004 112 1886376 112 1189765 112 1877267 开发者_StackOverflow中文版Output
111 1032192
111 2323476 111 1698881 111 2451712 112 2331004 112 1886376 112 1189765 112 1877267Thanks
Tony
awk '++count[$1] <= 4' input_file
($1 != curkey) { curkey=$1; i=0; }
(i < 4) { i++; print; }
精彩评论