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

names.txt Mike Millon 2 50000 Allen Border 1 2000 Gram Swan 8 150000 Steve Borde

ID: 3881328 • Letter: N

Question

names.txt

Mike Millon 2 50000

Allen Border 1 2000

Gram Swan 8 150000

Steve Border 3 6000

James Anderson 1 3000

Micheal Scott 4 6000

In this le, each line corresponds to an author who has worked with the publisher.
Each line has four elds, and they are, from the rst eld to the last, rst name, last
name, the number of books authored and the total number of copies printed (of all
the books that this author has written). A single space character is used to separate
two elds. The rst character of each rst or last name is capitalized, and the rest are
lowercase characters.

Use UNIX command sort, uniq, cut, cat, wc, head or tail to answer the question below.

Sort the lines of this le in decreasing order of the number of books authored.
That is, the rst line should be the author who has authored the largest number
of books (NOT the largest total number of copies printed). Your command
line should print the sorted lines to stdout.

Explanation / Answer

Unix command to sort the given lines in decreasing order of number of books authored.

sort -k3 -r -n names.txt

-k# This argument specifies which column to be used for sorting. Here 3rd column is used.

-r This reverse the sorting order.

-n This column specifies the "numeric" sort meaning that column should be interspersed as a row of numbers.