Linux Command (sort)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.