grep

I cant figure this out, new to Unix. Any help at all would be appreciated!

Suppose you were working a crossword puzzle and needed a 6-letter word beginning with 'b' (upper or lower-case) and with a lower-case 'e' as its third letter. What grep command would you use to list the words from /usr/dict/words that match this requirement?
I'm a bit rusty with regular expressions, but how about

grep   '^[bB].e.\{3\}$' /usr/dict/words 


that is, IF there is always a newline after the end of the word.
Last edited on
The regex is "^[Bb].e"
But is this related to C++?
Last edited on
It is not, related just running in through an SSH
Bazzy, wouldn't that skip the requirement for the word to have exactly 6 letters?

... wait, mine does that too.


grep '^[bB].e[a-z]\{3\}$' /usr/dict/words


This should do the job.
Last edited on
YES! Thanks
Just a fix I just came up with, you should replace the dot after [bB] with [a-z] otherwise it will also match numbers and stuff, which is probably not what you want.
Topic archived. No new replies allowed.