如何仅查找包含两个连续元音的行

时间:2018-10-25 12:25:13

标签: regex linux

如何查找包含连续元音的行

$ (filename) | sed '/[a*e*i*o*u]/!d'

1 个答案:

答案 0 :(得分:1)

要查找包含连续元音的行,应考虑使用

sed -n '/[aeiou]\{2,\}/p' file

此处,[aeiou]\{2,\}模式匹配2个或更多的匹配项(\{2,\}是一个间隔量词,最小匹配数设置为2),而[aeiou]是一个括号表达式匹配其中定义的任何字符。

-n禁止输出,p命令仅打印特定的行(即,-np仅输出与您的模式匹配的行)。 / p>

或者,您可以使用grep获得相同的功能:

grep '[aeiou]\{2,\}' file
grep -E '[aeiou]{2,}' file

这里是online demo

s="My boomerang
Text here
Koala there"
sed -n '/[aeiou]\{2,\}/p' <<< "$s"

输出:

My boomerang
Koala there