LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2007, 12:40 AM   #1
BlueNotes
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Rep: Reputation: 0
Can I search for a number that is less than 55 using grep?


Hello everyone.
I have created a bash shell script that reads another file and outputs the students names and grades based on the option used with the command.
Example.

Doe John A 86 Math

I have used the cut command along with grep to display on the first name, last name and mark.
choice=$1
case "$choice" in
-a)cut -f1,1,3 datafile | grep -e [8][0-9]
;;
-b) cut -f1,1,3 datafile | grep -e [7][0-9]
esac
My problem is I need to add an option which will display the students that have a grade lower than 55. I'm not sure how I can achieve this with grep. There are 12 students in the datafile, and their grades range from 29-100%.
After I solve that problem I have to add an option which will give me the class average, but first things first.
Oh, I can't use awk simply because I don't know how to use it, and I'm not supposed to know it yet. Yes it's a school thing.
Any help would be appreciated
Thanks.

Last edited by BlueNotes; 11-09-2007 at 01:19 AM.
 
Old 11-09-2007, 12:45 AM   #2
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Since this is homework I'll just point you in the right direction, at least what i think is the right direction

use grep to get the numbers, use bash for the math.
good luck
 
Old 11-09-2007, 12:47 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Use better thread titles. Is it really that difficult?
 
Old 11-09-2007, 07:37 AM   #4
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
You basically have it now. The only thing that you really need to change is the regular expression that you are using in your grep statement. Look into how to use the "|" in regular expressions as an or. From there, you should be able to coble it together. This is really handy to learn as you can use this in case statements as well if you want to do a certain action on a range of values.
 
Old 11-11-2007, 07:01 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,349

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
That seems a bit of an odd way to get the data (-f1,1,3 twice(!)), wouldn't the -d option in cut be easier ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:49 PM.

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