Shell Basics (iii) Sort usage

Source: Internet
Author: User

Shell Basics (iii) Sort usage

Syntax:sort [-t delimiter] [-KN1,N2] [-nru]

Here n1<n2

-T followed by delimiters, acting like cut-d,

-N uses a purely numeric sort, only for numbers, and if it's a letter, it's handled by 0 .

-R Reverse Sort

-U to repeat

-kn1,n2 from N1 interval to N2 interval, you can write only-kn1, that is, to sort N1 fields,cut intervals with a minus sign, sort with a comma, expressed .

Note: -T and-K are to be used together;

Sort without any options, sorted by acsii, not purely numbers or letters

# HEAD-N2/ETC/PASSWD

Root:x:0:0:root:/root:/bin/bash

Bin:x:1:1:bin:/bin:/sbin/nologin

Sort without any options, sorted from the first letter, by ASCII value comparison , output in ascending order.

# head-n2/etc/passwd |sort

bIn:x:1:1:bin:/bin:/sbin/nologin

ROot:x:0:0:root:/root:/bin/bash

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/8E/DC/wKioL1jN7jeClWLWAAAUMHExP_0162.png-wh_500x0-wm_ 3-wmp_4-s_2517500961.png "title=" SS. PNG "alt=" Wkiol1jn7jeclwlwaaaumhexp_0162.png-wh_50 "/>

-T followed by a delimiter,-K followed by a number, which is ordered by the string;-n means sorting using pure numbers

# head-n5/etc/passwd |SORT-T:-k3-n

Root:x:0: 0:root:/root:/bin/bash

Bin:x:1: 1:bin:/bin:/sbin/nologin

Note:-k3,5 represents a string sort at the 3rd to 5th zone level (cut using-f3-5 or-c3-5),-R for reverse ordering

The third paragraph to the fifth paragraph, first row third paragraph, if there are more than one line in the third paragraph, then according to the fourth paragraph row, if the fourth paragraph also has more lines, the fifth paragraph row.

# head-n2/etc/passwd |SORT-T:-k3,5

Root:x:0:0:root:/root:/bin/bash

Bin:x:1:1:bin:/bin:/sbin/nologin

# head-n2/etc/passwd |SORT-T:-k3,5-r

Bin:x:1:1:bin:/bin:/sbin/nologin

Root:x:0:0:root:/root:/bin/bash

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/8E/DE/wKiom1jN8KPxcjo9AAAhOu8jQ1s882.png-wh_500x0-wm_ 3-wmp_4-s_1260520418.png "Title=" oo. PNG "alt=" Wkiom1jn8kpxcjo9aaahou8jq1s882.png-wh_50 "/>

-N is used with-u, sort will look at the letters in the document as 0

# cut-d:-f1/etc/passwd |sort-n-U

Root

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/8E/DC/wKioL1jN8rKzrVp8AAAPaoSTrM0430.png-wh_500x0-wm_ 3-wmp_4-s_2969934476.png "title=" RR. PNG "alt=" Wkiol1jn8rkzrvp8aaapaostrm0430.png-wh_50 "/>

#vim 1.txt

1

1

2

2

3

3

4

4

Ab

Bc

Ef

#sort-n 1.txt "digit size, letters sorted by 0, if the document does not have a number, all characters will be considered 0"

Ab

Bc

Ef

1

1

2

2

3

3

4

4

#sort-U 1.txt "to repeat, and not know how much to repeat, where to repeat."

1

2

3

4

Ab

Bc

Ef

#sort-nu 1.txt "treat all the letters as 0, and repeat to show the top one."

Ab

1

2

3

4

Note: If there is a line in the document that is all punctuation marks, if-N is ordered, it is displayed in the first row.

,.,.,..,.,...

Ab

Bc

Ef

1

1

Omitted below


This article is from the "Wu Fei" blog, please be sure to keep this source http://wutengfei.blog.51cto.com/10942117/1908063

Shell Basics (iii) Sort usage

Related Article

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.