Linux Shell(二)

原创
2016/11/27 11:58
阅读数 55

排序sort

删除重复uniq

消除的操作是依据匹配的键值,而非匹配的记录

与sort通过pipeline配合使用

$ cat latin-numbers

tres

unus

duo

tres

duo

tres

$ sort latin-numbers | uniq   显示唯一的、排序后的记录,重复则仅取唯一行

$ sort latin-numbers | uniq -c  计数唯一的、排序后的记录

$ sort latin-numbers | uniq -d  仅显示重复的记录

$ sort latin-numbers | uniq -u  仅显示未重复的记录

重新格式化段落fmt

经典示例:linux系统中路径/usr/share/dict/words或/usr/share/lib/dict/words,使用命令

sed -n -e 9991,10010p /usr/share/dict/words | fmt   可重新格式化20个字典单词

sed -n -e 9995,10004p /usr/share/dict/words | fmt -w 30    可重新将10个单词格式化为短的行

计算行数、字数以及字符数

经典示例:

$ echo This is a test of the emergency broadcast system | wc

1    9    49

1:行数-l

9:字数-w

49:字节数-c/-m

另一个也比较常用:

wc /etc/passwd /etc/group    计算两个文件里的数据

49   78 2336 /etc/passwd
  64   64  924 /etc/group
 113  142 3260 total
 

最后关于打印,只说一点,也是最重要的一个知识点:

提取开头或结尾数行

head -n n / head -n / awk 'FNR <= n' / sed -e nq / sed nq

这些是等价的

tail -n n / tail -n / ...

tail -n n -f /path/to/*.log

下一节将重点讲述和管道相关的那些事儿,请持续关注,谢谢!

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
1 收藏
0
分享
返回顶部
顶部