开发者

Printing first four lines per key

开发者 https://www.devze.com 2023-01-22 00:12 出处:网络
I would like to print the first 4 lines by field 1 using awk Input 111 1032192 111 2323476 111 1698881 111 2451712

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 1877267

Thanks

Tony


awk '++count[$1] <= 4' input_file


($1 != curkey) { curkey=$1; i=0; }
(i < 4)        { i++; print; }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号