This exercise was useful for seeing how you can build more complex command pipelines in Unix using fairly simple commands. Learning how to call the manual for each command was also very helpful for understanding how a command behaves by default and how you can modify a command. It was also a useful exercise for learning how input and output works in command line. Nothing in this exercise was particularly challenging, but it was a good exercise for building my knowledge and comfort-level with working in command line.
Challenge Questions
When running
sorton the original file, the program is sorting by characters. By adding-nwe are telling the program to sort the values as numerical values.In
wc -l < mydata.datwe are telling the program to take the standard input from themydata.datfile. Whereas,wc -l mydata.datis using a command line parameter to tell the program what file to open and perform word count.Adjacent duplicated lines in datasets could be a sign of data entry mistakes, so it is useful for the
uniqcommand to simply remove all duplicates that are adjacent to each other. By adding thesortcommand, one could first put the lines in alphabetical order and then useuniqto remove duplicates with this final command:sort salmon.txt | uniq. This is another sign of how UNIX allows you to build more complex commands by combining simple commands using pipes.The first pipe
cat animals.txttells the program to concatenate all the files and since this is a single file it simply sends the contents of the file (output) to the next pipe as its input. Thehead -5takes the first 5 lines of the file, andtail -3takes the last three lines of these 5 lines, thensort –rsorts these three lines and then returns the results in reverse order. These three lines are then redirected into the temporaryfinal.txtfile instead of being printed as standard output. Essentially, thefinal.txtfile should contain line 3, 4, and 5 fromanimals.txtsorted in reverse order.You could add
sortto put the animal names in order and then useuniqto remove duplicates so the final command would be:cut –d, -f 2 animals.txt | sort | uniq.