How to find only the lines that contain two consecutive vowels

前端 未结 1 355
情书的邮戳
情书的邮戳 2021-01-24 15:13

how to find lines that contain consecutive vowels

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

1条回答
  •  醉梦人生
    2021-01-24 15:44

    To find lines that contain consecutive vowels you should consider using

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

    Here, [aeiou]\{2,\} pattern matches 2 or more occurrences (\{2,\} is an interval quantifier with the minimum occurrence number set to 2) and [aeiou] is a bracket expression matching any char defined in it.

    The -n suppresses output, and the p command prints specific lines only (that is, -n with p only outputs the lines that match your pattern).

    Or, you may get the same functionality with grep:

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

    Here is an online demo:

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

    Output:

    My boomerang
    Koala there
    

    0 讨论(0)
提交回复
热议问题