>>>Sort 命令常用相关选项:

选项说明
-c会检查文件顺序是否已排好序,如果乱序,则输出第一个乱序的行的相关信息,然后返回1
-k指定排序的列数
-b忽略每一行前面所有的空白行,从第一个可见的字符开始比较
-f将小写字母都转换成大写字母进行排序
-r反转降序
-u去除重复行
-o输出命名,重定向
-n按字符来排序
-t指定分隔符
-M以月份排序

例:[root@localhost ~]#sort -t: -k3n /etc/passwd


>>>uniq命令的作用:

选项说明
-c/--count在每列旁边显示除改行重复出现的次数
-d/--repeated仅显示重复出现的行列
-s<字符位置>忽略比较指定的字符
-u/--unique仅显示只有一次,不重复的行列
-w<字符位置>指定要比较的字符

[root@localhost ~]#骚cat a.txt 

12

22

34

22

12

12

22

56


[root@localhost ~]#骚sort a.txt |uniq -c

      1 

      3 12

      3 22

      1 34

      1 56



>>>join命令的作用:

 选项说明
-a FILENAMEFILENAME表示第几个文件,-a1表示第一个文件,-a2表示第二个文件
-e EMPTY若在FILE1与FILE2找不到指定的栏位,则在输出中填入-e选定的字符串
-i,--ignore-case比较时忽略大小写差异
-o FORMAT按照指定的格式显示结果
-v FILENUM-v 1表示只显示FILE1中与FILE2中没有相同栏位的行;
-v 2表示只显示FILE2中与FILE1中没有相同栏位的行:
-t CHAR使用栏位的分隔符
-1 FIELD链接FILE1指定的栏位
-j  FIELD等价与-1 FIELD -2 FIELD

例:

[root@localhost ~]#cat a.txt b.txt

1 abc

2 def

3 fun

4 hello

 

-------

1 beijing

2 we

3 fongguang

4

[root@localhost ~]#join a.txt b.txt

1 abc beijing

2 def we

3 fun fongguang

4 hello


>>>>>>把1.txt、2.txt、3.txt拼接起来成

[root@localhost ~]#cat 1.txt

1 january

2 February

3 March

4 April

5 May

6 June

7 July

8 August

9 September

10 October

11 November

12 December

 

[root@localhost ~]#cat 2.txt

2 Feb

3 Mar

4 Apr

6 June

7 July

9 Sept

10 Oct

5 May

1 Jan

11 Nov

8 Aug

12 Dec

 

[root@localhost ~]#vim 3.txt

1 一月

2 二月

3 三月

4 四月

5 五月

6 六月

7 七月

8 八月

9 九月

10 十月

11 十一月

12 十二月

 

[root@localhost ~]#sort -n 2.txt -o 4.txt

[root@localhost ~]#cat 4.txt

1 Jan

2 Feb

3 Mar

4 Apr

5 May

6 June

7 July

8 Aug

9 Sept

10 Oct

11 Nov

12 Dec

 

[root@localhost ~]#join <(join 1.txt 3.txt ) 4.txt

或者[root@localhost ~]#join 1.txt  3.txt |join - 4.txt

1 january 一月 Jan

2 February 二月 Feb

3 March 三月 Mar

4 April 四月 Apr

5 May 五月 May

6 June 六月 June

7 July 七月 July

8 August 八月 Aug

9 September 九月 Sept

10 October 十月 Oct

11 November 十一月 Nov

12 December 十二月 Dec

 

Join <(sort -n 2.txt) 1.txt|join – c.txt



>>>统计文本的行数:

[root@localhost ~]# cat -n a.txt |tail -1

    19

[root@localhost ~]# wc -l a.txt

19 a.txt

>>>查看文件里有多少个字

wc -w filename

>>>文件里最长的那一行是多少个字

wc -L filename    

 


>>>tail命令和head命令用于查看文件开头结尾部分

>>>可以实时监测命令运行,tail默认打印最后十行,head类比

>>>tail -c             显示文件最后的types个字节的字符

>>>tail -f /F         让更新的内容实时更新追加到显示里

>>>tail -n  20      显示尾部20行

>>>tail -r             倒序显示