LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-05-2006, 04:21 PM   #1
camaroblue87
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
Stuck on a Homework question


Ok i have a file named directory that contains this:

Computer Science 163 William St
Biology 1 New Plaza
Graduate Center 1 Smith Ave

And i am suposed to write a script that will take a department as a parameter and say if it is a match or not here is what i have so far.

Code:
#!/bin/sh
grep $1 directory
if(grep -w $1 `grep $1 directory` )
then
    echo there is a match
else
    echo no such department
fi
the problem is that grep returns the whole line and i dont know how to compare that to the parameter. like if i did

search "Biology"
grep "Biology" would return (Biology 1 New Plaza)

i think i need the if statment to compare like this
ie: if("Biology" = "Biology")


any ideas? thanks
 
Old 05-05-2006, 04:37 PM   #2
ataraxia
Member
 
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

Rep: Reputation: 30
Code:
#!/bin/sh
if(grep -q "$1" directory )
then
    echo there is a match
else
    echo no such department
fi
Quote your $1 in case there is a space in it.
"-q" for grep means "just say if it worked, don't print anything".
 
Old 05-06-2006, 09:52 AM   #3
camaroblue87
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks so much that worked great!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
homework help louce Linux - Newbie 3 09-04-2005 08:00 PM
stuck again (noob bash math question) babag Programming 6 04-25-2005 01:27 AM
Homework question, My code posted. ripwheels8 Programming 4 07-24-2004 01:25 AM
'security level' stuck [noob question] nocelery Linux - Security 2 04-08-2004 06:28 PM
Stumpt on a homework question klfreese General 7 08-23-2003 07:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration