简体   繁体   English

如何抓取过滤结果的数量

[英]How to grab filter the numbers of results

I use grep -E '^[ 0-9]{6}$' to grab strings of 5 digits (numbers or space) in files我使用grep -E '^[ 0-9]{6}$'在文件中获取 5 位数字(数字或空格)的字符串

It returns:它返回:

71 051
17 293
017299
862610

But is it possible to extract only the 2 first occurrences?但是是否可以只提取第一次出现的 2 次? If possible like this in this example "71051-17293"?如果可能的话,在这个例子“71051-17293”中是这样的吗?

Two options to grep only two lines max: grep 的两个选项最多只有两行:

$ grep -Em2 '^[ 0-9]{6}$'
71 051
17 293
$ grep -E '^[ 0-9]{6}$' | head -n2
71 051
17 293

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM