Small Grading Program

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

  2. Create a series of commands for a grading program.

Create a grades file. Put a "tab" between the name and grade. Run these commands directed to a file (>>).

Sam Smith A
Harry Konik B
Mike Grep C
Ann Smith A
Zed Arf F
Beth Mon B
Tod Bar C

a. Sort the list by last name
b. Sort the list by grade
c. Display all student's with A's
d. Display the number of students
e. Display the three top students
f. Display the two lowest grades
g. Display the list with the last name first followed by the first name then the grade.

  1. Relevant commands, code, scripts, algorithms:

sort, grep(?)

  1. The attempts at a solution (include all code and scripts):

Ok, before I start, I really am not sure what it means by "tab." Does it mean an actual tab, or a colon?

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Brookdale Community College - Lincroft, New Jersey - United States - Dr. Rick Bournique- COMP 145

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

---------- Post updated 03-31-13 at 09:01 PM ---------- Previous update was 03-30-13 at 10:26 PM ----------

Ok I created a file "namesfile" with tabs inbetween the first and lastname like so:

Sam     Smith A
Harry    Konik B
Mike     Grep C
Ann      Smith A
Zed      Arf F
Beth     Mon B
Tod      Bar C

My attempted solutions thus far:

a:

sort -k 1 namesfile

b:

sort -k 2 namesfile

d:

wc -l namesfile

c, e, f, and g are giving me a hard time, but I am still trying to figure them out.

Read more carefully where it said to put the tab.

Yes, a tab means a tab, not a colon, as you figured out.

Is there a difference between putting

[quote]
tabs inbetween the first and lastname

[quote]
as you did when you created namesfile and the requirement to

?

It would be highly unusual for any IT professional to use the term "tab" to refer to a colon character.

Has you study of regular expressions enabled you to construct an RE matching a particular character at the end of a line?

You might want to get clarification as to whether the two lowest grades are D and F or the two lowest grades that have been assigned to class members. You might also want to clarify how you are to determine the top three students when there are two students with an A and two students with a B.

Assignment g would be much easier with awk, read and (echo or printf), or sed than with just grep and sort. (Of course I'm making assumptions about what shell you're using for your class. You haven't given us any indication of what shell and what operating system you're using.)

You're right, thanks. I just thought it might be a colon, but it's not. A few things:

1) Why would adding the tab after the lastname matter though?

2) Is my solution to part d correct, or is counting the line numbers not accurate (NOTE: This is intro stuff so I tend to think if it's too easy it must be wrong, so this is probably the right solution(?))

3) For f, it is the two lowest grades that have been assigned to class members.

4) For e, I just emailed him to clarify.

5) For assignment G we have not learned awk yet. I'm 90% sure he does not want us using things we have not learned in class. So what on earth would I use, because many examples I googled use awk?

Read the instructions again from the professor for exactly where to put the tab. (Hint: the tab does NOT go after the first name :)).

If the assignment does not list awk as a possible solution, do NOT use awk. I'm 100% sure he does not want you using things you have not learned in class. What other commands have you learned in class?

I know, I updated it so it is after the last name there is a tab. I'm just wondering what the tab does :slight_smile:

Here are the commands that are relevant for this lab from the slide for this chapter:

File level commands:

pr
cmp, comm, diff
sort
uniq

Content level commands:

head,tail
cut, paste
tr
grep

I'm very surprised that you have a class where you are learning about UNIX system utilities, but a shell isn't among the utilities you've been taught to use. As I said before, using your shell's built-in read and echo or printf utilities in a while loop would seem to be an obvious choice for some of these tasks.

I'm also very surprised that you are not allowed to use a text editor to create your input file (or, if you have been taught how to use an editor, that sed hasn't also been included in your list of available commands).

I'm just wondering what the tab does

The tab is a "delimiter" or "separator". It says "everything to the left is the name, everything to the right is the grade". It's a convenient way of keeping track of "what is what". As you mentioned, a colon could have been used (as in the password file). But a tab is very commonly used. The reason the delimiter matters is because for example some of the names might have a middle name, so that needs to be anticipated and planned for:

John Doe A
Julie Ann Smith B
Jacob O. Cohen C
Here are the commands that are relevant for this lab from the slide for this chapter:

What about "wc"? Did they cover that? My guess is you might need wc for the assignment.