Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

unsortedNames.txt: N D Street Faye King Lenny R Graph I M Board Mark R Board Sal

ID: 3890726 • Letter: U

Question

unsortedNames.txt:

N D Street
Faye King
Lenny R Graph
I M Board
Mark R Board
Sal Ed Barr
Grey Wire
Holly Graph
Perry Scope
Bob L Head
Joe King
Holly Wood
Ava Kashun
Jean E Us
Mac A Ronee
E Racer
Hammond Ecks
B B Gunn
Cooke King
Tuck King
N D Carr
Otto Graph
Dee Boat
Anita Goodgrade

CS3423 Project 3: Using Awk This project has two parts. Part A. You have been provided an unsorted file of names /usr/local/courses/clark/cs3423/2017Fa/Proj3/unsortedNames.txt). Each name ends with a last name and may have multiple names and/or initials before the last name (unfortunately it varies). Use awk and sort to create a file sorted by last name. This may involve multiple awk and one sort step. The resulting sorted file should look similar to the original file except that it is sorted by last name. Hint: Since the number of words in a name varies, we need to create an intermediate that has the last name first to simplify sorting. After sorting, we no longer want that last name as the first value. Create a bash file named p3a.bash to create the sorted file. Besides the shebang line, there should be only one other line in the bash file. That line must use pipes between the steps.

Explanation / Answer

Below is the command when run in a prompt will give you output desired (awk and sort both is been used)

awk '{print $NF}' unsortedNames.txt | sort -u >lname.txt;while read line; do grep -w $line unsorted.txt; done<lname.txt

#Above awk script will sort the last column and redirects it to lname.txt file, which in turn is run on while loop to print the sorted file based on the last name on the prompt.