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 153. Find Minimum in Rotated Sorted Array
假设按照升序排序的数组在预先未知的某个点上进行了旋转。 ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 请找出其中最小的元素。 你可以假设数组中不存在重复元素。
79 0
LeetCode 153. Find Minimum in Rotated Sorted Array
|
算法
LeetCode Find Minimum in Rotated Sorted Array II
假设按照升序排序的数组在预先未知的某个点上进行了旋转。 ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 请找出其中最小的元素。 注意数组中可能存在重复的元素。
63 0
LeetCode Find Minimum in Rotated Sorted Array II
Leetcode-Easy 806. Number of Lines To Write String
Leetcode-Easy 806. Number of Lines To Write String
62 0
|
C++ Python
[LeetCode] Find Minimum in Rotated Sorted Array
As explained in the Solution tag, the key to solving this problem is to use invariants. We set two pointers: l for the left and r for the right.
709 0
|
Perl
[LeetCode] Find Minimum in Rotated Sorted Array II
This problem is more or less the same as Find Minimum in Rotated Sorted Array. And one key difference is as stated in the solution tag.
766 0
[LeetCode] 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? Suppose a sorted array is rotated at some pi
1177 0