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 acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop lcd malware memory missing monitor motherboard network operating system printer problem ram registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
simple grep command

Reply  
Thread Tools
netmaster's Avatar
Junior Member with 7 posts.
 
Join Date: Dec 2005
07-Dec-2005, 07: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 2,612 posts.
 
Join Date: Jul 2005
Experience: I've been at this for too long.
07-Dec-2005, 08:38 PM #2
grep -e "[cC]ompote" filename
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
07-Dec-2005, 09: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, 09: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
07-Dec-2005, 09:17 PM #5
Raspberry*a
netmaster's Avatar
Junior Member with 7 posts.
 
Join Date: Dec 2005
07-Dec-2005, 10: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 2,612 posts.
 
Join Date: Jul 2005
Experience: I've been at this for too long.
07-Dec-2005, 10: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, 11:21 PM #8
Actually they are exam practice questions, not homework. Everything is complete at this point. Thanks for everyones help.
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
07-Dec-2005, 11: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
Member with 146 posts.
 
Join Date: Dec 2005
08-Dec-2005, 02: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?
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:00 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.