sort,uniq,cut常用指令

sort:

排序所有指定文件並將結果寫到標準輸出。

-u:去除重複行

-r:反向排序

-n:數值排序從小到大

-t:指定分段的符號

-k:指定的第幾個段

-b:忽略所有空白行

 

 [root@station141 ~]# sort Andy.txt
1
2
2
34
56
accp
benet
I'm sorry, Mr.
Three pineapple
Two watermelon
Water on the refrigerator
[root@station141 ~]# sort -u Andy.txt  去掉重複行
1
2
34
56
accp
benet
I'm sorry, Mr.
Three pineapple
Two watermelon
Water on the refrigerator
[root@station141 ~]# sort -r Andy.txt反向查詢
Water on the refrigerator
Two watermelon
Three pineapple
I'm sorry, Mr.
benet
accp
56
34
2
2
1
 [root@station141 ~]# sort -n Andy.txt
accp
benet
I'm sorry, Mr.
Three pineapple
Two watermelon
Water on the refrigerator
1
2
2
34
56
89

 

uniq等同於sort -u

 

-u:只顯示不重複的行

-d:只顯示重複的行

-c:顯示出現幾次

 

[root@station141 ~]# uniq Andy.txt
benet
accp
Water on the refrigerator
I'm sorry, Mr.
Two watermelon
Three pineapple
1
89
2
34
56
[root@station141 ~]# uniq -u Andy.txt
benet
accp
Water on the refrigerator
I'm sorry, Mr.
Two watermelon
Three pineapple
1
89
34
56
[root@station141 ~]# uniq -d Andy.txt
2
[root@station141 ~]# uniq -c Andy.txt
      1 benet
      1 accp
      1 Water on the refrigerator
      1 I'm sorry, Mr.
      1 Two watermelon
      1 Three pineapple
      1 1
      1 89
      2 2
      1 34
      1 56

 

 

cut:選取命令,把數據分析後,取出所需

-c:以字符爲單位進行分割

-f:與-d一起使用,顯示哪個區域

-d:自定義分割符。

-n:取消分割多字節字符

-b:以字節爲單位進行分割

[root@station141 ~]# echo 12:00:01 | cut -d ':' -f 1
12
[root@station141 ~]# echo 12:00:01 | cut -d ':' -f 1-
12:00:01

paste:將文件的行進行合併

-d:指定兩個文件的行合併後的分割符

-s:將每個文件合併爲一行,而不是按行進行合併

[root@station141 ~]# paste -d: Andy.txt Andy1.txt 
benet:afsdfsdf 
[root@station141 ~]# paste -s Andy.txt Andy1.txt

join:將兩個排序的文件相同內容合併爲一個文件

-an:顯示文件n中不匹配的文件行

-t:定義分隔符

[root@station141 ~]# vim 2.txt
1
2
3
4
5
6
7
8
9
0 
[root@station141 ~]# vim 1.txt
o
1
2
3
4
5
6
[root@station141 ~]# join 1.txt 2.txt
1
2
3
4
5
6
7

diff:文件相比較,找出不同點。

 和join完全相反
[root@station141 ~]# diff 1.txt 2.txt 
9c9,11
< 
---
> 8
> 9
> 0

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章