grep commands

Discussion in 'General Computing' started by CrazyRunner2311, Mar 11, 2014.

  1. CrazyRunner2311

    CrazyRunner2311 New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    I have been working on this shamefully for over 6 hours.

    Suppose you were working a word puzzle and needed a 5-letter word beginning with 'd' (upper or lower-case) followed immediately by a lower-case vowel (including 'y') and ending with 's'. The remaining letters could be any character that occurs in English words, including upper and lower-case alphabetics, hyphens, etc. (We will accept the file /usr/share/dict/words as the authority on what constitutes a valid English word.)

    What grep command would you use to list the words from /usr/share/dict/words that match this requirement?

    I am running this via ssh in terminal on my mac.

    I have tried various assortments of grep & egrep command lines and am not getting anywhere.

    What command would you enter to see 5-letter words that begin with 'd' (upper or lower-case), followed by a lower-case vowel, and ending in 's'?

    egrep '[dD][aeiouy][a-zA-Z]{2}s' /usr/share/dict/words

    No. That's not it.
    An example of a word that you accepted, though you should not have, is: Adidas

    when i try to add a parameter for word length before the letter specs the system crashes.
    IE: ' [1-5]


    I am at a loss. I have read online tutorials and purchased two linux/unix books from barnes an noble can someone please explain this to me and where I am making my error?
  2. thrivequake

    thrivequake New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    egrep '^[dD][aeiouy][a-zA-Z]{2}s$' /usr/share/dict/words
  3. MikeyD

    MikeyD Active Member

    Messages:
    232
    Likes Received:
    113
    Trophy Points:
    43
    egrep "^[Dd][aeiouy]..s$"

    Might work, although '.' may pick up characters you don't want not sure.

    Also you forgot the ^ anchor in thrivequake's post, which is why Adidas matched.
    Last edited: Mar 12, 2014
  4. mavankhang

    mavankhang New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    egrep "^[Dd][aeiouy]..s$"

Share This Page