27.9. sort - sort lines of text files

简介:
$ du -s * | sort -k1,1rn
	
$ rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
$ dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1n
	

27.9.1. 对列排序

sort -k 具体说来, 你可以使用 -k1,1 来对第一列排序, -k1来对全行排序

# sort -t ':' -k 1 /etc/passwd
		
ort -n -t ‘ ‘ -k 2 file.txt
		

多列排序

$ sort -n -t ‘ ‘ -k 2 -k 3 file.txt
		

27.9.2. -s, --stable stabilize sort by disabling last-resort comparison

例如: 如果你要想对两例排序, 先是以第二列, 然后再以第一列, 那么你可以这样. sort -s 会很有用

 sort -k1,1 | sort -s -k2,2		
		

Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
[leetCode 第1题] -- Find Minimum in Rotated Sorted Array
题目链接: Find Minimun in Rotated Sorted Array 题目意思: 给定一个旋转数组,找出这个旋转数组的最小元素。旋转数组的定义是,把一个从小到大排好序的数组,取一部份放到末尾,例如0 1 2 4 5 6 7 取 0 ...
859 0
Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 首先我是要AVL树的创建过程进行操作,不过提交之后出现超时,但还是让我将AVL树的创建过程实现了一遍,...
869 0
Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
748 0
|
算法 C++
Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? ...
763 0
Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the array. 思路:如果中间节点的值最大,则取后半部分,如果中间节点的值最小,则取前半部分。
747 0
|
9月前
|
存储 分布式计算 搜索推荐
sort-10-bigfile sort 大文件外部排序
这是一个关于排序算法系列的概述,包括冒泡排序、快速排序、选择排序、堆排序、插入排序、希尔排序、归并排序、计数排序、桶排序和大文件外部排序。大文件排序通过文件拆分、独立排序、合并排序和优化合并步骤实现,尤其适用于不能一次性加载到内存中的数据。该方法的时间复杂度为O(n log n),空间复杂度为O(n)。文章提供了一个Java实现的`BigFileSort`类,用于大文件的排序操作。代码中使用了归并排序的策略进行合并,并考虑了磁盘I/O的影响。完整代码可在GitHub的开源项目中找到。
|
C++ 人工智能
Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a funct...
617 0

热门文章

最新文章