如何使用egrep列出与正则表达式匹配的单词? [英] How do I use egrep to list words that match a regular expression?
问题描述
我需要使用egrep来计算包含与正则表达式匹配的字符串的字。例如,我需要做一些例如计算包含三个连续元音的单词数(不完全是这个,但这是它的要点)。
我知道如何计算包含这些单词的行,但是当我添加-w标签时,我得到一个 egrep:illegal选项 - w
错误。 p>
这是一个正则表达式,我将用于计算上述场景中的行,这似乎有效:
egrep -i -c'[aeiou] [aeiou] [aeiou]'full.html
使用此命令使用 -w
标记会导致上面列出的错误,即使我在正则表达式周围添加了\b标记。例如:
egrep -i -c -w'\b。* [aeiou] [aeiou] [aeiou] \b'full.html
我做错了什么?
编辑:我在Solaris 10上运行此终端。
还要查找包含字符串的单词的数量
grep --color -Eow'[aeiou] [aeiou] [aeiou]'filename | wc -l </ code>
或
egrep -ow '[aeiou] [aeiou] [aeiou]'filename | wc -l </ code>
o仅打印匹配的。
最后,它将显示该字的计数。
I need to use egrep to count words that contain strings which match a regular expression. For instance, I need to do something like "Count the number of words containing three consecutive vowels" (not exactly that, but that's the gist of it).
I've figured out how to do it to count lines which contain these words, but when I add the -w tag I get an egrep: illegal option -- w
error.
Here's the regular expression I'd use to count lines in the scenario above, which seems to work:
egrep -i -c '[aeiou][aeiou][aeiou]' full.html
Using the -w
tag with this command causes the error I listed above, even if I add \b tags around the regex expression. e.g.:
egrep -i -c -w '\b.*[aeiou][aeiou][aeiou].*\b' full.html
What am I doing wrong?
EDIT: I'm running this on Solaris 10 out of the terminal.
use this way also to find the count of the words that contains strings
grep --color -Eow '[aeiou][aeiou][aeiou]' filename | wc -l
or
egrep -ow '[aeiou][aeiou][aeiou]' filename | wc -l
o for Print only the matched.
w for word.
finally, it will display the count of the word.
这篇关于如何使用egrep列出与正则表达式匹配的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!