Shell Practice-sort Sort by detailed

Source: Internet
Author: User

There is a log file on the server Guest.log, each line contains: ID number, name, Internet café Name, the most recent Internet time, Internet hours, the amount of consumption, now requires the file of each row of the sixth column and the second column to be removed in accordance with the consumption amount of reverse output to another file Test.log, please give the shell command?

awk "{Print $6 $}" Guest.log|sort-rn-o Test.log

Sort

1. Principle :

Sort compares each line of a file as a unit, comparing it from the first character backwards, followed by the ASCII value, and then outputting it in ascending order.

2. Parameter Introduction

-U output result de-weight

-R default ascending,-R descending output

-N is sorted by numeric value, no n option, 19:2 small cases appear

-O Avoid redirection to the original file is content is lost

- T -k-t can specify a delimiter-K to specify which part of-T:-K 3 is delimited by a colon, and the third paragraph

-F ignores case (converted to uppercase for comparison)

-C checks whether the file is sorted successfully, does not sort successfully, outputs information about the related row, and returns 1

-C Check whether the file is sorted successfully, not sorted successfully, only returns 1

-B ignores blank portions of each row, starting with the first valid character

For example:

1.txt has the following contents (name: Gender: Age)

Liming:boy:13

Wangsan:boy:12

Liling:girl:14

To sort by age in reverse, you can: sort-t:-K 3-rn 1.txt

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/86/8D/wKioL1fDx8KgtG-eAABHLHW5N3I134.jpg-wh_500x0-wm_3 -wmp_4-s_317572192.jpg "title=" sort.jpg "alt=" Wkiol1fdx8kgtg-eaabhlhw5n3i134.jpg-wh_50 "/>

problem thinking and testing : If you add-u the same age people are not only show a

Liming:boy:13

Wangsan:boy:12

Liling:girl:14

Liming2:boy:13

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/86/8D/wKiom1fDyDyRxbksAABOS0iCp8I517.jpg-wh_500x0-wm_3 -wmp_4-s_3683047817.jpg "title=" sort1.jpg "alt=" Wkiom1fdydyrxbksaabos0icp8i517.jpg-wh_50 "/>

As the results show, plus-u removes the same rows as the comparison section






This article is from the "Share,open source" blog, so be sure to keep this source http://liqilong2010.blog.51cto.com/3029053/1843842

Shell Practice-sort in a detailed order

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.