- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 100字
- 2021-07-09 19:46:20
How it works...
As shown in the examples, sort accepts numerous parameters to define how the data is to be sorted. The sort command is useful with the uniq command, which expects sorted input.
There are numerous scenarios where the sort and uniq commands can be used. Let's go through the various options and usage techniques.
To check whether a file is already sorted, we exploit the fact that sort returns an exit code ($?) of 0 if the file is sorted and nonzero otherwise.
if sort -c fileToCheck ; then echo sorted ; else echo unsorted ; fi