Regex 使用grep匹配数字流行(字节)中的前两位(仅)
我应该如何使用grep在一个方向上(即Regex 使用grep匹配数字流行(字节)中的前两位(仅),regex,grep,Regex,Grep,我应该如何使用grep在一个方向上(即01051015中的01而不是10)匹配数字流行(1字节行)中的前两位(仅第一次出现); 我接受了测试: 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
01051015
中的01
而不是10
)匹配数字流行(1字节行)中的前两位(仅第一次出现);
我接受了测试:
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
grep-E'^[0-9]\{2\}$'| grep-Po--color“01”matchedList.txt
$cat-n matchedList.txt
1 0001021113
2 0202031011
3 0103031113
但我需要解析并计算第一个“par出现”(在本例中为“10”)。。。按照特定顺序和一个方向(如第2行);因此,正确的输出应该是:2 0203031011
Tkx提前
L
其中:
是您要查找的第一个2位01
第一次出现的限制-m1
grep -m 1 -e '^01' YourFile