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 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.