sort text sorting

1. Command function

sort sorts the contents of the input file according to the specified rules, and then outputs the sorted contents.

2. Syntax

sort  option  file

Parameter Description

parameter

Parameter Description

-b

Ignore spaces at the beginning of each line

-n

Sort by size of string value *

-r

reverse order

-u

remove duplicate lines

-t

Specify the delimiter

-k

Sort by interval

3. Example of use

[root@localhost ~]# cat test.txt

172.16.0.2

172.16.0.8

172.16.0.4

172.16.0.3

Example 1 sort does not take any parameters.

The default comparison method of sort, from the first letter backward, is compared according to the ASCII code, and the output is sorted in ascending order by default.

[root@localhost ~]# sort test.txt

172.16.0.2

172.16.0.3

172.16.0.4

172.16.0.8

Example 2 Sort numerically by -n

[root@localhost ~]# sort -n test.txt

172.16.0.2

172.16.0.3

172.16.0.4

172.16.0.8

Example 3 -r sort descending

[root@localhost ~]# sort -r test.txt

172.16.0.8

172.16.0.4

172.16.0.3

172.16.0.2

Example 4

[root@localhost ~]# cat test.txt3

ACBDE

ACBDE

12345

[root@localhost ~]# sort -u test.txt3

12345

ACBDE

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324886450&siteId=291194637