使用grep匹配数字流行(字节)中的前两位(仅)



我应该如何使用grep在一个方向上匹配数字流行(1字节行)中的前两位(仅第一次出现),即(01,而不是01051015中的10);我接受过测试:

grep -E '^[0-9]{2}$' | grep -Po --color '01' <<< 01051015
> 010-10-- (current output)
$cat -n test.txt
1 0001021113
2 0202031011
3 0103031113
4 .......... 
$ grep -oE '^[0-1][0-9]{2,2}' | grep -E '(10)' ./test.txt > matchedList.txt
$ cat -n matchedList.txt 
1 0001021113 
2 0202031011 
3 0103031113 

但我需要解析和计算第一个"par occurrence"(在本例中为"10")。。。按照特定的顺序和一个方向(如第2行);因此正确的输出应该是:2 0202031011

Tkx提前L.

grep -m 1 -e '^01' YourFile

其中:

  • 01是您要查找的第一个2位
  • -m 1限制为第一次出现

最新更新