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 81. Search in Rotated Sorted Array II
假设按升序排序的数组在事先未知的某个枢轴处旋转。 (例如, [0,0,1,2,2,5,6] 可能变成 [2,5,6,0,0,1,2]). 给定一个要搜索的目标值T, 如果该目标值能在数组中找到则返回true,否则返回false。
103 0
LeetCode 81. Search in Rotated Sorted Array II
LeetCode - 33. Search in Rotated Sorted Array
33. Search in Rotated Sorted Array  Problem's Link  ---------------------------------------------------------------------------- ...
753 0
|
C++
[LeetCode] Search in Rotated Sorted Array II
For those who have already solved Search in Rotated Sorted Array, this problem can be solved similarly using codes for that problem and simply adding codes to skip the duplicates.
895 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.
794 0
|
C++ Python
[LeetCode] Search in Rotated Sorted Array
This problem is a nice application of binary search. The key lies in how to determine the correct half for target.
575 0