Linux Command (sort)
Sort command
The sort command is very useful in linux. It sorts files and fired standard output for sorting. The sort command can get input from either a specific file or stdin.
Syntax
Sort (option) (parameter)
Option
-B: Ignore the leading space character of each line.
root@68fc0a9bc6dd:/home/wzm/testsort# sort sortfile1 ccc aaa bbbbroot@68fc0a9bc6dd:/home/wzm/testsort# sort -b sortfile1 aaa bbbb ccc
-C: Check whether the files are arranged in order.
root@68fc0a9bc6dd:/home/wzm/testsort# sort -c sortfile1sort: sortfile1:2: disorder: cccroot@68fc0a9bc6dd:/home/wzm/testsort# cat sortfile1 aaa ccc bbbb
-D: When sorting, other characters except English letters, numbers, and spaces are ignored.
root@68fc0a9bc6dd:/home/wzm/testsort# sort sortfile1 @@@@a 1#######c 3%%%%%%%%%%%%%%%%%b 2root@68fc0a9bc6dd:/home/wzm/testsort# cat sortfile1 @@@@a 1#######c 3%%%%%%%%%%%%%%%%%b 2root@68fc0a9bc6dd:/home/wzm/testsort# sort -d sortfile1 @@@@a 1%%%%%%%%%%%%%%%%%b 2#######c 3
-F: When sorting, lowercase letters are considered as upper-case letters (regardless of the size of the letter)-I: When sorting, except for ASCII characters between 40 and 176, other characters are ignored. -K <Number of columns>: specifies the number of columns, which must be used with-t
root@68fc0a9bc6dd:/home/wzm/testsort# sort -k 2 -t , sortfile2bbb,aaa,cccAAA,ccc,bbbroot@68fc0a9bc6dd:/home/wzm/testsort# cat sortfile2AAA,ccc,bbbbbb,aaa,ccc
-M: sorts the first three letters by the abbreviation of the month. -N: sort by number. -O <output file>: stores the sorted structure into a custom file. -R: sort in reverse order. -T <separator>: Specifies the column Separator Used for sorting. The example is in the-k example. + <Start column>-<End column>: sort by the specified column. It does not work.
root@68fc0a9bc6dd:/home/wzm/testsort# sort +1 -2 sortfile1 @@@@a 1%%%%%%%%%%%%%%%%%b 2#######c 3root@68fc0a9bc6dd:/home/wzm/testsort# cat sortfile1 @@@@a 1#######c 3%%%%%%%%%%%%%%%%%b 2
-U: Remove duplicate rows.