grep pattern for getting words having alternate consonants and vowels

I have a text file file1.txt containing the following words

  • abcdefghis
  • abacadafag
  • cdefghijka
  • bedefegehj
  • cidifigihi

Question: How will I get the words with alternating consonants and vowels using grep pattern?
My expected output is like this:


So far I have this code but it only displays words with alternating consonant and vowel on the first 2 characters.

cat file1.txt | grep -i '^[^aeiou][aeiou]'

Any help would be appreciated. Thanks. 🙂

Source: unix

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.