sort

来源:互联网 发布:吴鹰 知乎 编辑:程序博客网 时间:2024/04/29 06:32

一.Sort

一般形式:

sort – options output_file [other options] + pos 1 +pos2 input_files

 

1.       Sort 按第一域进行分类

$ sort –t : video.txt

2.       Sort 按第一域逆向分类

$ sort –t : -r video.txt

3.       唯一性分类,-u 可去除重复的行

$ sort –u video.txt

4.       按指定域分类,使用k

$ sort –t : -k4 video.txt

$ sort –t : -k4 –k1 video.txt

5.       使用headtail将输出分类

$ sort –t : -r  -k4 –k1 video.txt | head -1 将分类结果显示第一行

$ sort –t : -r  -k4 –k1 video.txt | tail -2将分类结果显示后两行

$ head -3 filename 查阅前3

$ tail -7 filename查阅后7

6.       将两个文件分类,使用-m

$ sort –t :  -m video2.txt video.txt

二.Uniq

一般形式:

uniq  -options –f input-file output-file

1.       只去掉连续重复的行

uniq myfile.txt

2.       只显示不重复的行 –u

uniq -u myfile.txt

3.       显示重复行,每个重复行显示一次 –d

uniq -d myfile.txt

4.       打印每一个重复行出现的次数 –c

uniq -c myfile.txt

三.join

         一般形式:

         Join options input-file1 input-file2

1.       连接两个文件

join file1 file2

2.       显示匹配和不匹配域

join  -a1 –a2 file1 file2

3.       选择性连接 –o

join –o 1.1 2.2 file1 file2 将第一个文件的第一个域和第二个文件的第二个域连接

四.cut

         一般形式:

         cut options filen

1.       剪切指定字符

$ cut –c1 file 剪切内容为每一行的第一个字符

$ cut –c1-3 file剪切内容为每一行的第一个到第三个字符

$ cut –c1,3,5 file剪切内容为每一行的第一个、第三个字符和第五个字符

         2.剪切指定域

$ cut –f1 file剪切第一个域

$ cut –f1,3 file剪切第一个和第三个域

五.paste

         一般形式:

         Paste  -d –s file1 file2

1.       $ paste file1 file2

2.       $ paste –d: file1 file2

3.       $ paste -s file1 file2

六.split

         一般形式:

         split –out-flie-size input-filename output-filename

1.       $ split -2 split1  按每个文件两行分割

原创粉丝点击