Reprint Shell Sort

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_6d09b5750100x6zg.html

The first is the shell sort implementation of multi-column sorting, here to add a vertical line to split, the following file test:

a|gggg|4|7b|fff2|3|2c|gea0|6|12d|kkkg|4|11e|uity|6|4f|fger|1|3g|wabg|7|5h|zhag|8| 7i|hang|3|3j|lang|2|15k|long|5|7$cat Test |sed ' s/|//g ' |sort-k3,3n-k4,4nr of course, here can not remove the vertical line, directly with the-t option to sort the original text, you need to escape the pipe, with "\|" : $cat Test |sort-t\| -k3,3n-k4,4nr we can do without the pipe symbol: $sort-T\| -K3,3N-K4,4NR Test in a file by column sorting needs to be spaced, so using sed to use the vertical bar in the file "|" The output is converted to spaces, sort "-k3,3n" is sorted by the third column (key) and ordered (Numeric-sort), "-k4,4nr" is output in reverse order by fourth column (reverse), and results in a similar order by ROW3 in the SQL statement DESC, that is, priority to the Row1 sort, in the results, if row3 the same, on the same basis, the row4 is sorted, here the third to fourth column is ascending and descending, the result is F Fger 1 3j Lang 2 15i hang 3 3b FFF2 3 2d kkkg 4 11a G GGG 4 7k Long 5 7c gea0 6 12e uity 6 4g WABG 7 5h Zhag 8 7 Other sort $cat Test |sed ' s/|//g ' |sort-k3,3nr-k4,4nr$cat test |sed ' s/|//g ' |sort-k3,3n-k4,4n should be easy to analyze. By accessing the shell command in the program, you get the contents of the file (for example, the Popen function in PHP, the fgets function to get the data, and the explode to split the array. can be accessed in the Web), as if data were obtained from the data, but the database can be paged through the limit Lines1,lines2, what about the file? We can do this through the tail and head of the shell command, with the number of rows specified, as follows 10 lines, +1 starting from the first row, and the last line of the end of the file if there is no "+" sign. This is achieved through the combination of tail and head, a display 10 rows of the first page: $tail-n +1 |head-n 10 such as the 3rd page: $tail-n +31 |head-n 10 as for eachHow much the page is displayed (that is, 10 in the command), just write it

Reprint Shell Sort

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.