Using grep and regular expressions, I need to output all lines in a file that contain at least six characters in a row that aren't vowels. This includes any consonants, punctuation, numbers, etc.

  • 4
    Okay. Did you try anything yourself? – heemayl Apr 3 at 18:33
  • 4
    do my homework for me please – Gilles Quenot Apr 3 at 18:36
  • Would you please click edit and add to the original question what you're written so far? It's always best, FYI, to expand your original question, which assures all can see the enhancement, rather than reply-by-Comment. Comments pile up, and scroll under the screen after a while. – K7AAY Apr 3 at 18:36
  • 1
    In what locale? Å, Ä and Ö are vowels... – Kusalananda Apr 3 at 19:22

This should do the trick:

Ex="[^AEIOUaeiou]"; grep -E "$Ex$Ex$Ex$Ex$Ex$Ex" myfile

  • Why the -E? Unless, of course, you instead did grep -E "$Ex{6}", but that would render the use of that variable useless. – Kusalananda Apr 3 at 19:18
  • grep -E "[^AEIOUaeiou]{6}" myfile – steve Apr 3 at 19:19
  • 2
    Or grep -iE '[^aeiou]{6}' – Kusalananda Apr 3 at 19:21
  • -E means use expression (egrep can be used too). And yes, the use of {6} and -i is more eloquent than a variable. – Colin Pearse Apr 4 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.