Assume you have a file with integers, one per line. Your job is to take that file as an argument and print the maximum and minimum values in the file. How can that file be loaded and processed from the Terminal?
1 Answer
Sort the file with sort --numeric-sort file.txt
The minimum value is the first line of the sorted file: sort --numeric-sort file.txt | head -1
The maximum value is the last line of the sorted file: sort --numeric-sort file.txt | tail -1