how many words in the file /usr/share/dict/american-english have exactly two letters x?
print all the words in the file /usr/share/dict/american-english that have exactly two letters b, but not together. For example: baby is OK, while lobby is not
i was told to use egrep
i am not sure its the right way
anyway i cant get it done i lloked in the man nothing was tald about those problems what option of egrep to use
how do i build it?
Jeff Rummings
Ranch Hand
Joined: Dec 20, 2007
Posts: 42
posted
0
Have you tried to do it? Post what you came up with so far.
johny doe
Ranch Hand
Joined: Dec 07, 2007
Posts: 78
posted
0
i looked in the manual of this command i didnt find there any clues with option to work?? can you give me a hint [ January 11, 2008: Message edited by: johny doe ]
Jeff Rummings
Ranch Hand
Joined: Dec 20, 2007
Posts: 42
posted
0
You could for example
1) find all matches with 2 b's 2) exclude results with more than 2 b's 3) exclude results where b's are consecutive
You can use pipes '|' to redirect output from one command to another
I would recommend that you start with his step 1. Show us what command you used to get that, and a couple of lines of the output.
At some point you will probably need to use regular expressions. The man page for grep should give you some information on that. However I would recommend you get some sort of output from step 1 before delving too deeply into the regular expressions.
i found a way how to find the word which have a pair of the same letter
but what i am looking for is the opposite thing word wich the pair of the same letters are separated like:
baby
Doug Slattery
Ranch Hand
Joined: Sep 15, 2007
Posts: 294
posted
0
Hi Johny,
Regular expressions will make your challenge far easier to solve once you understand them.
I'll assume you have the looping part of iterating through all the words in the dictionary covered...
grep uses regular expressions (I take it you figured that out already and I don't mean to insult your intelligence), but the man pages on [e]grep as Arman suggests (at least the ones I've seen) don't delve too deeply on regular expressions. There should be a "See Also" section at the bottom of the man page which will point you to the regex definition.
With that being said, here's a description of how I would approach the problem you're facing:
First off, regex isn't a programming language or anything like that that would allow you to count the number of a particular letter (or pattern) in a string. In your case, each word is a string. Think of regex as a notation for matching substring patterns within a string. The man pages discuss how to construct the substrings. A substring is considered a pattern and you can have multiple patterns in an expression. This is just what you need. To find a pattern consisting of an 'x' followed by another 'x' and no more. To back up a microsec from that statement, regular expressions are evaluated from left to right in the main string until the first pattern (substring) is matched. If there are more patterns, the main string continues to be evaluated after the last character from the previous pattern matched.
Armed with this information, here's the pseudo logic for the problem: Search from the beginning of the string and find an 'x' pattern. Continue searching after the first 'x' for another 'x' pattern Continue searching after the second 'x' for no more 'x' patterns. If the above three steps work, print the word.
I suspect the third step may give you a stumble with the regex notation. Give it a try and post your results.
Aloha, Doug
-- Nothing is impossible if I'mPossible
Jeff Rummings
Ranch Hand
Joined: Dec 20, 2007
Posts: 42
posted
0
You could also read a few tutorials on the web. To get you started, take a look at these ones: