# simple grep command



## netmaster (Dec 5, 2005)

Here is a question that I could not figure out how to do:

Display a list of all of the lines in the file that contain "Compote" or
"compote"

Strawberry Jam,300,191
Raspberry Jam,1216,194
Blueberry Jam,96,195
Strawberry Compote,49,621
Raspberry Compote,1937,624
Blueberry compote,200,625
Frozen Strawberries,130,1941
Straw Hats,16,2047

This is basically a simple grep command. However, I cannot use the grep -i option, which is really frustrating. 

Anyone know a solution?


----------



## jiml8 (Jul 3, 2005)

grep -e "[cC]ompote" filename


----------



## Squashman (Apr 4, 2003)

jiml8 said:


> grep -e "[cC]ompote" filename


That is probably the easiest way or you can put all your search terms in a file and use the -f option.


----------



## netmaster (Dec 5, 2005)

the command worked, thanks. Although the -e extension was nescessary. One last question though...

Display all of the lines in the file that contain "Raspberry" followed later
in the line by the letter "a".

I believe that this question uses the wildcard, but I'm not sure how to follow up with the letter "a"


----------



## Squashman (Apr 4, 2003)

Raspberry*a


----------



## netmaster (Dec 5, 2005)

Squashman said:


> Raspberry*a


Thank you for your help sir, that was not quite correct. The answer was...

grep "Raspberry.*a" inventory

anyways...the final question is:

Display all of the lines in the file where the last field is 4 digits long.

Search for "," before the field to make sure your regular expression matches
the whole field, use character classes to match four digits, and anchor it
to the end of the line to make sure it's the last field.

Anyone know this?


----------



## jiml8 (Jul 3, 2005)

netmaster said:


> Thank you for your help sir, that was not quite correct. The answer was...
> 
> grep "Raspberry.*a" inventory
> 
> ...


Are we doing your homework for you? I think you need to figure this one out for yourself (I have the answer here but it sure looks like you are supposed to be doing this).


----------



## netmaster (Dec 5, 2005)

Actually they are exam practice questions, not homework. Everything is complete at this point. Thanks for everyones help.


----------



## Squashman (Apr 4, 2003)

netmaster said:


> Thank you for your help sir, that was not quite correct. The answer was...
> 
> grep "Raspberry.*a" inventory


It was correct for what you were asking.


----------



## ghostdog74 (Dec 7, 2005)

netmaster said:


> Here is a question that I could not figure out how to do:
> 
> Display a list of all of the lines in the file that contain "Compote" or
> "compote"
> ...


If i did not read the question wrongly, it says just display the lines where
there is either 'Compote' or 'compote' right?

grep -i compote can definitely list them out. Does your "grep" have the -i option?


----------

