table of Contents
- sort tool
- uniq tool
- tr tool
-
- The specific command statement format of tr is
- Its common options include the following
- usage
-
- Convert input characters from uppercase to lowercase
- Replace all characters that are not in the first character set
- Delete all characters that are not in the first character set
- Compress repeated characters in input
- Delete the characters in the first character set that are more than the second character set and replace them
sort tool
Sort according to different data types
- Character sort (default)
- Number sort
Grammar format
sort [options] parameter
Common options
- -f: Ignore case
- -b: Ignore the spaces in front of each line
- -M: Sort by month
- -n: sort by number
- -r: reverse sort
- -u: equivalent to uniq, which means that only one line of the same data is displayed
- -t: Specify the separator, use [Tab] to separate by default
- -o <output file>: dump the sorted results to the specified file
- -k: Specify the sort area
usage
Sort the accounts in the /etc/passwd file (default character sorting)
[root@server2 ~]# sort /etc/passwd
Sort the third column in the /etc/passwd file forward and backward
[root@server2 ~]# sort -n -t ":" -k 3 /etc/passwd
[root@server2 ~]# sort -n -t ":" -rk 3 /etc/passwd
Export the reverse sort results to the specified file zhfx.txt
[root@server2 ~]# sort -n -t ":" -rk 3 /etc/passwd -o zhfx.txt
[root@server2 ~]# cat zhfx.txt
uniq tool
Common options
- -c: count
- -d; only show duplicate lines
- -u: only display lines that appear once
usage
View automatic merge of duplicate rows
[root@server2 ~]# vi testfilel
[root@server2 ~]# uniq testfilel
Repeat count of duplicate rows
[root@server2 ~]# uniq -c testfilel
Only show duplicate rows that appear and show the number of occurrences
[root@server2 ~]# uniq -cd testfilel
Show only lines that occur once
[root@server2 ~]# uniq -u testfilel
tr tool
The specific command statement format of tr is
- tr [options] [parameters]
Its common options include the following
- -c: Replace all characters that do not belong to the first character set
- -d: delete all characters belonging to the first character set
- -s: represent the continuously repeated characters as a single character
- -t: first delete the characters in the first character set more than the second character set, and replace them
usage
Convert input characters from uppercase to lowercase
[root@server2 ~]# echo "GHHH" | tr 'A-Z' 'a-z'
Replace all characters that are not in the first character set
[root@server2 ~]# echo "bcd123bcd123" | tr -c bc 44
Delete all characters that are not in the first character set
[root@server2 ~]# echo "happy new year" | tr -d 'ae'
Compress repeated characters in input
[root@server2 ~]# echo "Itttttt was an appleeeeeeeee" | tr -s 'te'
Delete the characters in the first character set that are more than the second character set and replace them
[root@server2 ~]# echo "bcd123bcd123" | tr -t 'bcd' 'e'
[root@server2 ~]# echo "bcd123bcd123" | tr -t 'bcd' 'eee'
[root@server2 ~]# echo "bcd123bcd123" | tr -t 'bc' 'efg'