grep question͏͏

I’m currently stuck on a question for my Unix course that requires us to search for any words that have the following characteristics. I was wondering if anyone could assist in crafting such a command, as it’s far more convoluted than anything I’ve done before. The characteristics for a word in the English language are as follows.

It must …

  1. be exactly 5 characters long
  2. begin with an upper or lowercase vowel (a, e, i, o, u, or y)
  3. have a lowercase ‘t’ in the middle position.
  4. end with a lowercase ‘s’
  5. The rest of the characters can be any character that occur in English words; i.e, uppercase, lowercase, hyphen, numbers, etc.

So far I’ve gotten something like this.


within brackets and such. 
All of this must be using grep and use /usr/share/dict/words to find what the command reads. 
I just need to know what parameters to use. Pretty dang confusing.

The main issue I’m finding is ensuring the first character is uppercase OR lowercase, whilst ensuring the remaining characters can be interchangeable as uppercase or lowercase.

Asked By: Vordt


/usr/dict/words has one word per line.

The main thing you are missing are the anchors to match the beginning and/or end of the word. As words are one per line, you can use ^ and $ which match the start and end of string (line).

grep '^[AEIOUYaeiouy].t.s$' /usr/dict/words

Lots of versions of regular expression tools have extensions to allow word boundaries, e.g.,

grep '<[AEIOUYaeiouy].t.s>' /usr/dict/words
Answered By: icarus
 grep "^[aeiouAEIOU]" filename
Answered By: user534104
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.