1 Cut: Split the file in some way and then output
Option:-B Select by byte
-D Custom Delimiter
-F and-D are used together to specify which area or field
[Email protected] ~]# CAT/ETC/PASSWD | Cut-d:-F 1 #以: Prints the first field as a delimiter
[email protected] ~]# Cat B.txt | Cut-b 2-3 #取每行的第2到第3字节
2 Sort: Text sort
Options:-N Sort by value
-R sorted in reverse order
-F Ignore case when sorting
-T Specify delimiter
What interval to sort by-K
[Email protected] ~]# sort Cc.txt #默认从首字符向后依次排序
11
22
22
33
34
5
[Email protected] ~]# sort-n cc.txt #按数值排序
5
11
22
22
33
34
[Email protected] ~]# Sort-rn cc.txt #按降序排列
77
56
56
56
55
34
[Email protected] ~]# CAT/ETC/PASSWD | Sort-t:-K 3-n #以: For delimiters, take third field by value
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
3 Uniq: Count or delete duplicate rows
Option:-C count the number of repetitions and print them out
-D displays only duplicate rows
[Email protected] ~]# Uniq-c cc.txt | Sort-rn
3 56
2 22
1 77
1 55
1 5
[Email protected] ~]# uniq-d cc.txt
22
56
4 TR: Character processing
[Email protected] ~]# tr-d "s" < B.txt #删除文件中的s字符
[Email protected] ~]# tr-d ":" </etc/passwd #删除文档中的: No.
[email protected] ~]# Cat B.txt | tr [A-z] [a-z] > aa.txt #把小写替换成大写并且保存为aa. txt file
This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1917214
The text processing of Linux