[Shell Foundation]--sort Command

Source: Internet
Author: User
Tags pear

Sort command
Sort is output in ascending order of ASCII code, and is compared sequentially from the first character

Common options
-C test file is already sorted

-R Reverse Sort
-N Sort by numeric numeric size

-t Specifies the separator
-K Specify Domain

-U removes duplicate rows from the result
-m merge two sorted files
-O writes output to the specified file


(1)-u sort after removing duplicate rows

# Cat 1.txt1:datadir=/aaa/zzz:2:basedir=:cc4:datadir=/sdfsfsd:dd3:basedir=/data:ggsnsdsnsdsnsdsnsdsnsdsnsd# Cat 1. TXT | Sort-u1:datadir=/aaa/zzz:2:basedir=:cc3:basedir=/data:gg4:datadir=/sdfsfsd:ddsnsdsnsdsnsd


(2)-N

# cat 2.txt110111925# Cat 2.txt | Sort    ---> #sort是按照ASCII码升序输出, 110111925# cat 2.txt | sort-n  ---> #为实现纯数值排序可用-n from first character backwards Option Implementation 125101119


(3)-R reverse Order

# Cat 2.txt | Sort-n-r191110521


(4)-t-k

# cat-n 3.txt1 banana:30:5.52 apple:10:2.53 pear:90:2.34 orange:20:3.4# cat 3.txt | sortapple:10:2.5banana:30:5.5orange:20:3.4pear:90:2.3# Cat 3.txt | Sort-t ': '-3-n  ---> #以: As a delimiter, sorted by the numeric size of the 3rd field pear:90:2.3apple:10:2.5orange:20:3.4banana:30:5.5# Cat 3.txt | sort -T ': '-K 3-n-R  ---> #以: for delimiters, reverse-order the numeric size of the 3rd field banana:30:5.5orange:20:3.4apple:10:2.5pear:90:2.3

[Shell Foundation]--sort Command

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.