linux uniq sort 排重、排序
来源:互联网 发布:免root备份游戏数据 编辑:程序博客网 时间:2024/05/21 14:53
有如下文件a.txt
[root@m95] /ftproot# cat a.txt
ttt|000001
uuu|000002
uuu|000002
uuu|000002
uuu|000002
1
2
3
4
5
6
7
77
8
9
9
=====================================
#cat a.txt | uniq -c -i | sort -k2 -n 排重,排重输出的第二列正序排列
#cat a.txt | uniq -c -i | sort -k2 -rn 排重,排重输出的第二列逆序排列
uniq 参数解释
-c 统计重复数量
-c Precede each output line with the count of the number of times
the line occurred in the input, followed by a single space.
-d Only output lines that are repeated in the input.
-f num Ignore the first num fields in each input line when doing compar-
isons. A field is a string of non-blank characters separated
from adjacent fields by blanks. Field numbers are one based,
i.e., the first field is field one.
-s chars
Ignore the first chars characters in each input line when doing
comparisons. If specified in conjunction with the -f option, the
first chars characters after the first num fields will be
ignored. Character numbers are one based, i.e., the first char-
acter is character one.
-u Only output lines that are not repeated in the input.
-i Case insensitive comparison of lines.
=============================================================================
linux关于sort命令的高级用法(按多个列值进行排列)
如果单纯地使用sort按行进行排序比较简单,
但是使用sort按多个列值排列,同时使用tab作为分隔符,而且对于某些列需要进行逆序排列,这样sort命令写起来就比较麻烦了
比如下面的文件内容,使用[TAB]进行分割:
Group-ID Category-ID Text Frequency----------------------------------------------200 1000 oranges 10200 900 bananas 5200 1000 pears 8200 1000 lemons 10200 900 figs 4190 700 grapes 17
下面使用这些列进行排序(列4在列3之前进行排序,而且列4是逆序排列)
* Group ID (integer) * Category ID (integer) * Frequency “sorted in reverse order” (integer) * Text (alpha-numeric)
排序后的结果应该为:
Group-ID Category-ID Text Frequency----------------------------------------------190 700 grapes 17200 900 bananas 5200 900 figs 4200 1000 lemons 10200 1000 oranges 10200 1000 pears 8
可以直接使用sort命令来解决这个问题:
BASH CODE
sort -t $'\t' -k 1n,1 -k 2n,2 -k4rn,4 -k3,3 <my-file>
解释如下:
-t $'\t':指定TAB为分隔符-k 1, 1: 按照第一列的值进行排序,如果只有一个1的话,相当于告诉sort从第一列开始直接到行尾排列n:代表是数字顺序,默认情况下市字典序,如10<2r: reverse 逆序排列,默认情况下市正序排列
所以最后的命令:sort -t $’\t’ -k 1n,1 -k 2n,2 -k4rn,4 -k3,3 my-file
- linux uniq sort 排重、排序
- sort排序 和 uniq排重
- Linux去重 排序 计数 分隔 命令 awk sort wc uniq
- linux中sort排序和uniq
- linux---排序命令 sort,wc,uniq
- Linux命令去重统计排序(awk命令去重,sort, uniq命令去重统计)
- sort对输出行排序排重
- linux sort uniq -c
- linux sort uniq -c
- 【linux】 sort and uniq
- Linux Sort & Uniq
- linux sort/uniq 使用
- linux uniq,sort
- Linux管线命令之排序命令(sort, wc, uniq)
- 排序命令: sort, wc, uniq
- 排序命令: sort,uniq,wc
- linux uniq去重
- 去重复和排序【sort】【uniq】
- LoadRunner调用Java程序—性能测试
- HP LoadRunner 11.00 尝鲜
- 共享的艺术之:Samba服务的搭建
- Ubuntu 12.04创建桌面启动器方法
- android开发-常用色彩
- linux uniq sort 排重、排序
- 为什么手机多用arm?
- 使用stty修改终端设置
- SQL Server数据库的备份与还原(.NET项目)
- 在java中将int转成String
- 求一元二次方程的根
- [原创]LoadRunner如何测试WebService
- 15个幻灯片效果的JQuery插件
- Oracle中TO_DATE TO_CHAR格式