HELP! Grep...

Jeslek

Banned
Hi, I need some help with grep. I am not quite sure how to work with it. Yet. So I'm trying to teach myself a bit from a book and the man pages, but I'm not having much luck. I got a few questions from the book but no answers, so if anyone could assist me here I would be grateful. Anyways, I'm using the command

grep -E RegularExpression /usr/dict/words

where RegularExpression is going to be what I need help with:

(1) All lines which are non-empty and only contain the lowercase letters c through s.

"^[c-s]*$" seems to be doing it. Is there an easier way?



(2) All lines with at least two instances of the lowercase vowel "i", each of which occurs before the first instance of any other lowercase vowel (a, e, o, or u). For example, "biblical" and "childlike" are valid but "abolition" is not.

--don't have the foggiest idea what to do



(3) All lines with at least two occurrences of "st". "ST", "St" and "sT" do not count as occurrences of "st".

"(st){2,}" doesn't work :/ And I don't quite know what is wrong. It is not the / slash thing problem. I tried it with / before the parentheses and it still doesn't work.



(4) All lines that contain only lowercase letters, have at least five characters and do not contain a "real" lowercase vowel (i.e., by real vowel, we mean a, e, i, o, or u. Why? y not.)

I don't quite get how I can specific 5 letters AND a filter. I know you can use the period (.) as a placeholder, but how would I incorporate it with a filter?



(5) All lines which contain "foo" or "bar" in the "middle" of the line. For example, "football," "bar" and "foolish" are not such words, but "barefoot", "embark" and "barbarian" are. Note that middle is not the exact middle, but rather, something which is not at the head or end of the line.

".((foo)|(bar))+." seems to be doing it. Is this correct?



(6) All lines which contain the sequences "os" and "so". For example, "virtuoso" and "crossover" are such words, but "whose" and "wholesome" are not.

"((oso)|(osso))+" seems to be doing it. Is this correct?
 
I don't know about grep, it looks like you need a lexical analyzer, something that flex can also do.

For flex just make your grammars and you're done.

For syntactical and semantical analysis use bison, it is completely compatible with flex.
 
Back
Top