Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop drivers dvd email error excel excel 2003 firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
simple grep command

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
netmaster's Avatar
Junior Member with 7 posts.
 
Join Date: Dec 2005
07-Dec-2005, 06:46 PM #1
simple grep command
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's Avatar
Senior Member with 1,513 posts.
 
Join Date: Jul 2005
Experience: I've been at this for too long.
07-Dec-2005, 07:38 PM #2
grep -e "[cC]ompote" filename
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
07-Dec-2005, 08:04 PM #3
Quote:
Originally Posted by jiml8
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's Avatar
Junior Member with 7 posts.
 
Join Date: Dec 2005
07-Dec-2005, 08:08 PM #4
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's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
07-Dec-2005, 08:17 PM #5
Raspberry*a
netmaster's Avatar
Junior Member with 7 posts.
 
Join Date: Dec 2005
07-Dec-2005, 09:02 PM #6
Quote:
Originally Posted by Squashman
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's Avatar
Senior Member with 1,513 posts.
 
Join Date: Jul 2005
Experience: I've been at this for too long.
07-Dec-2005, 09:37 PM #7
Quote:
Originally Posted by netmaster
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?
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's Avatar
Junior Member with 7 posts.
 
Join Date: Dec 2005
07-Dec-2005, 10:21 PM #8
Actually they are exam practice questions, not homework. Everything is complete at this point. Thanks for everyones help.
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
07-Dec-2005, 10:35 PM #9
Quote:
Originally Posted by netmaster
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's Avatar
Senior Member with 130 posts.
 
Join Date: Dec 2005
08-Dec-2005, 01:05 AM #10
Quote:
Originally Posted by netmaster
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?
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?
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 03:37 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.