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.
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