我需要计算一个10位数字出现在文件中的实例总数.所有数字都有前导零,例如:
This is some text. 0000000001
Run Code Online (Sandbox Code Playgroud)
返回:
1
Run Code Online (Sandbox Code Playgroud)
如果相同的数字出现多次,则会再次计算,例如:
0000000001 This is some text.
0000000010 This is some more text.
0000000001 This is some other text.
Run Code Online (Sandbox Code Playgroud)
返回:
3
Run Code Online (Sandbox Code Playgroud)
有时在数字之间没有空格,但应计算每个连续的10位数字符串:
00000000010000000010000000000100000000010000000001
Run Code Online (Sandbox Code Playgroud)
返回:
5
Run Code Online (Sandbox Code Playgroud)
如何确定文件中出现的10位数字的总数?
Nat*_*ate 19
试试这个:
grep -o '[0-9]\{10\}' inputfilename | wc -l
Run Code Online (Sandbox Code Playgroud)