Understand the multiple arguments of the sort command in Linux
- 2021-01-03 21:15:21
- OfStack
The sort command is very common, but it also has a lot of arguments, such as -o, -n, -u, -r1. Here is one question, which can be well combined with the above parameters to achieve a good memory effect.
Title: Data file data contains the following data:
4
1
3
5
1001
2
4
5
Sort in reverse with 1 command, de-rerun and save the data again in the data file. Final output:
[
1001
5
4
3
2
1
To achieve the above three requirements, we need to use the above parameters at the same time, the specific command is as follows:
[root@localhost ~]# cat data | sort -nur -o data
1001
5
4
3
2
1
Remark:
-u parameter # deweight -ES35en parameter # sorted by natural number instead of ASCII -ES37en parameter # descending order The -ES38en parameter # writes the file to a file instead of standard outputconclusion