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

the whole thing is using putty and use emacs to create the file Step 14: A pipe

ID: 3748592 • Letter: T

Question

the whole thing is using putty and use emacs to create the file

Step 14: A pipe for practice. We will used the file names created earlier. Remember that the file has the following contents: Alan Turing Alan Turing Ken Thompson Alan Turing Alan Byron Ken Byron Ada Byron Develop a single command line that prints the number of distinct last names in the above file on the screen. The output should be 3 in this example. Once you get the command line ready, copy it into the file cmd14'. Note that this file must contain the actual command line, not the output of the command. In order to write a pipeline command (or pipe' for short) have in mind that this is done by connecting several commands with the pipe symbol '1. This was mentioned in class. The first command should probably include the file name since it will be reading from the file and writing to the standard output. The next command will read this output as its input, so it does not need a file to specified. Each next command will also read output of the previous command and will not need a file name to be specified. If you want to test the command that you wrote in the file, you can do it using the command: source cmdl 4

Explanation / Answer

NOTE: I have completed answer for your question. Please check and let me know if you have any questions. I will get back within a days time. Thanks for your patience.

Command output:
Unix Terminal> cat file.txt|cut -d' ' -f2|sort -u
Byron
Thompson
Turing
Unix Terminal>


Explanation:
1) Please create the file.txt with below contents then run the above command.
Alan Turing
Alan Turing
Ken Thompson
Alan Turing
Alan Byron
Ken Byron
Ada Byron

2) cat file.txt
reads contents from file.txt

3) cat file.txt|cut -d' ' -f2
contents from file.txt are read and passed as input to cut command to get the second column which is a last name. As the first and last names are separated by space we have used space as delimiter(-d) for the cut command

4) cat file.txt|cut -d' ' -f2|sort -u
the last names obtained are sorted and then unique output is obtained using sort -u(sort and make uniq)