正则表达式找到匹配模式

时间:2014-02-03 11:25:27

标签: regex awk grep

我需要解析这种文字:

Some text and some 9539 934580 numbers Total number = 45 and then some more text

我需要提取这个:

输出:

Total number = 45

匹配空格......

(数字与线路不同)

如何在正则表达式中获得此模式?

提前致谢

1 个答案:

答案 0 :(得分:2)

正则表达式为:

Total number = \d+

Total number = [0-9]+

您可以将其与grep

一起使用
grep -E -o 'Total number = [0-9]+' inputfile > outputfile

-o选项告诉它只打印匹配行的部分。