Can I get some help?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can I get some help?
# 1  
Old 05-06-2008
Can I get some help?

I've only started learning UNIX 2 days ago since my supervisor wanted me to. She gave me some exercises which I successfully answered thanks to google and UNIX tutorials. But this one is taking me longer than usual so I come here to seek for help. Smilie

This is the exercise she gave me:
>> User will prompted to search for either by last name (-l) or first name(-f). The script named as searchcomp will get the exact matching parameter based from input.txt and display the breakdown of other details.
Format of execution will be like below:
searchcomp [-l] [-f] ‘pattern’
ex. searchcomp -f 'Tang'
Output will be:

First Name: <first name field>
Last Name: <last name field>
Exercise 1: <grade of exercise 1>
Exercise 2: <grade of exercise 2>
Case Study: <grade of case study>
Average: 15% of exer1 + 15% of exer2 + 70% of case study
Remark: ‘Fail’ for 74 below
‘Pass’ for 75 above
<<
Input.txt looks like this:
>>
LastName:FirstName:Exer1:Exer2:Case:
Tang:Sam:90:40:40
Dylan:Tom:80:48:50
Smith:John:34:67:89
...
<<
I don't have any problems with getting the average or whether its pass or fail. But I'm kinda stumped on how to get the firstname. My idea was to grep it then I really don't know how to seperate them since I can't put it in a seperate file. I'm nto allowed. So if the results of the grep were.
Ex.

Tang:Sam:90:40:40
Tang:Kim:94:78:40

I'm not sure how I can seperate the Tang as the lastname and Sam as a firstname? or the exercises? Is there any way to traverse the line/string? I'm also thinking if there were multiple results, I would have to seperate them as well. Am I on the right path or is my algorithm for solving this wrong? Any help would be appreciated with this, thanks

Last edited by kdyzsa; 05-06-2008 at 12:37 AM..
# 2  
Old 05-06-2008
Quote:
...I don't have any problems with getting the average or whether its pass or fail. But I'm kinda stumped on how to get the firstname.
How come you don't have problems getting average when you don't know how to split them?

Do "man cut" on the unix prompt to know about separation based on a delimiter - it is quite simple. Also read a bit about "awk" - it is extremely powerful for this kind of data manipulation.

HTH
# 3  
Old 05-06-2008
Oh

I meant I wouldn't have any problems getting the average once I have the numbers. Thanks though for your input. I'm looking up 'cut' right now
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question