-1

I have a file including thousands of lines where the term Found is followed by a numerical value and another term document(s). I would like to be able to match the pattern string+numerical+string and only extract the numerical value as I will need to find out what is the smallest and largest number.

4

2 回答 2

1

只是一个正则表达式模板

string \s* (\d+) \s* string

数字在捕获缓冲区 1 中的位置。

于 2013-11-14T19:37:03.887 回答
0

感谢您的回复。我必须指定我正在使用 bash shell 在 Linux 中工作我想出的解决方案是:

cat filename.txt | grep -w -o "string [0-9]\{1,\} string" > output.txt

这使我可以匹配任何大于 1 的数字并将字符串-数字-字符串模式列表输出到文本文件。

谢谢,

我。

于 2013-11-17T22:24:15.773 回答