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: 3881329 • 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.

Print the rst name and the last name of the author for whom the total number
of copies printed (NOT the number of books authored) is the largest among
all authors. Your command is supposed to print the rst name and the last name
only, without printing anything else.

Explanation / Answer

The unix command is as follows :

cut -d " " -f 1,2 | tail -n 1 | sort -k 4 names.txt

Sort - sort is a simple and very useful command which will rearrange the lines in a text file so that they are sorted, numerically and alphabetically. 'k' defines the key field using ehich the lines are to be sorted .

Tail - The tail command, as the name implies, print the last N number of data of the given input.As the last line contains the record with highest number of copies printed after sorting . We extract only the last line of the file .

Cut - The cut command in UNIX is a command for cutting out the sections from each line of files and writing the result to standard output. Just cut the first name and last name .