Linux Text Processing Tools
WC Print the number of lines, words, and bytes
cut split text by column
Sort Sorts
uniq Eliminating duplicate rows
WC print the number of lines, words, and bytes
Grammar:
WC [OPTION] ... [FILE] ...
Options:
-l:line count rows
-w:words statistics of words
-c:characters Statistic character Count
Example:
[[email protected] ~]$ cat Wctesthello World 123[[email protected] ~]$ wc-l wctest #统计行数1 wctest[[email protected] ~]$ Wc-w wctest #统计单词数3 wctest[[email protected] ~]$ wc-c wctest #统计字符数16 wctest
Cut split text by column
Grammar:
Cut OPTION ... [FILE] ...
Options:
-D delimiter: Indicates delimiter (can be used without spaces)
-F fields: Specifying a field
#: Section # Fields
#,#[,#]: Discrete multiple fields, such as 1,3,6
#-#: Multiple consecutive fields, such as 1-6
Mixed use: 1-3,7
--output-delimiter=string #把string换成想要的分隔符就成
Example:
[Email protected] ~]# cut-d:-F 1,7/etc/passwd #以: Displays columns 1th and 7th for separation [[email protected] ~]# cut-d: -F 1,7--output-delimiter= '/etc/passwd #把: delimiter changed to space
Sort sorts
Grammar:
Sort [OPTION] ... [FILE] ...
Options:
-F: Ignore character case
-R: Reverse order
-t:delimiter: Delimiter
-K #: Sort the specified fields as standard
-N: Sorting by numeric size
-u:uniq, remove duplicate display after sorting
[[email protected] ~]# sort-t:-k3-n/etc/passwd #以: Delimiter sorted by numeric size [[email protected] ~]# sort-t:-k3-n/ ETC/PASSWD |cut-d:-f3 #接上, see more clearly
Uniq Eliminating Duplicate rows
Grammar:
Uniq [OPTION] ... [INPUT [OUTPUT]]
Options:
-C: Shows the number of occurrences per line
-D: Show only rows that have been repeated
-U: Show only rows that have not been duplicated
Note: Repeat for continuous and identical sides
[Email protected] ~]# history | Cut-d '-f5 | Sort-u #查看历史命令, sort-u remove duplicate [[email protected] ~]# history | Cut-d '-f5 | Uniq #使用uniq命令, the same command that is not contiguous still displays [[email protected] ~]# history | Cut-d '-f5 | Sort | Uniq[[email protected] ~]# history | Cut-d '-f5 | Sort | Uniq-c #使用uniq-C, can show the repetition several times
Exercise: separated by a colon, take the 6th to 10th lines of the/etc/passwd file, sort the information by the numeric size of the 3rd field, and then show only the respective 1th fields
[Email protected] ~]$ CAT/ETC/PASSWD | Head-n 10|tail-n 5|cut-d:-f3 | sort-n567810
This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1845384
Linux Text Processing Tools