Text Processing commands:
Cut ,sort ,WC ,uniq
Cut Select a paragraph in a piece of information, and the information is processed in "Rows".
syntax:cut OPTION ... [FILE] ...
Parameters:
–d ' separators '
–f # Segmentation by character, showing section #
#, #,#: 1,3,5 shows the information ofparagraph 1, 3, and5
#-#:2-4 Display The information in paragraphs 2 through fourth
–c # Remove fixed-character intervals in units of characters for orderly processing
#- Displays the value after the # characters
#-# display values for the selected interval
Example
[Email protected] test]# cat test_cuthow are you? how old are you? where are youfrom? how do it? #以? For the separator, the 2nd message is displayed [[email protected] test]# cut -d '? ' -f 2 test_cut howold are you# Displays the 2nd and 4th paragraphs with the? ]# cut -d '? ' -f 2,4test_cut howold are you? how do it# Displays the 2nd to 4th paragraph with the? protected] test]# cut -d '? ' -f 2-4test_cut howold are you? where are you from? how do it# Displays the contents after the 8th character [[email protected] test]# cat test_cutaaaa 1 how are you ?aaaa 1 how old are you?aaaa 1 practice make pefectaaaa 1 so good! [[email protected] test]# cat test_cut | cut -c 8- howare you ? howold are you? practice make pefectso good!
Sort Sort
syntax:sort [OPTION] ... [FILE] ...
Parameters:
-F: Ignore case
-B: Ignores the first whitespace part
-M: Sort by the name of the month,
-N: Sorting using "number"
-R: Reverse sort
-U: Quite with Uniq, go repeat
-T: delimiter, TAB is used by default
-K: Which interval field to sort ( and T to use )
Example
#默认按第一个文字排序 [[email protected] test]# cat /etc/passwd | sortabrt:x:173:173::/etc/ abrt:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinapache:x:48:48:apache:/var/www:/sbin/ nologinavahi-autoipd:x:170:170:avahi ipv4llstack:/var/lib/avahi-autoipd:/sbin/nologinbin:x:1:1:bin:/bin:/ Sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologindbus:x:81:81:system messagebus:/:/sbin/nologinftp:x : 14:50:ftp user:/var/ftp:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingdm:x:42:42::/var/lib/ gdm:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologin# Reverse Sort-r[[email protected] test]# cat /etc/passwd | sort-rvcsa:x:69:69:virtual console memoryowner:/dev:/sbin/ Nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinusbmuxd:x:113:113:usbmuxduser:/:/sbin/nologintcpdump:x : 72:72::/:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncsshd:x:74:74:privilege-separatedssh:/var/empty/sshd:/ sbin/nologinshutdown:x:6:0:shutdown:/sbin:/sBin/shutdownsaslauth:x:498:76:saslauthduser:/var/empty/saslauth:/sbin/nologinrtkit:x:499:497:realtimekit:/proc :/sbin/nologinrpc:x:32:32:rpcbinddaemon:/var/cache/rpcbind:/sbin/nologinrpcuser:x:29:29:rpc serviceuser:/ After the var/lib/nfs:/sbin/nologin# is split, sort by the established field [[email protected] test]# cat /etc/passwd | sort-t ': ' -k 3 -nroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/ nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/ sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/ Sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Uniq : To repeat
syntax:uniq [OPTION] ... [INPUT [OUTPUT]]
Parameters:
-I: Ignore uppercase and lowercase letters
-C: Counting
Example:
# to repeat [[email protected] test]# Last | Cut-d '-F 1 |sort | Uniq rebootrogerrootwtmp# count repetitions [[email protected] test]# Last | Cut-d '-F 1 |sort | UNIQ-C 1 5 reboot Roger Root 1 wtmp
WC: number of words, lines, characters in the statistics file
syntax:WC [OPTION] ... [FILE] ...
WC [OPTION] ...--files0-from=f
Parameters:
-L: list only travel
-W: Lists only the number of words
-M: How many characters
Example:
#同时系统中有多少用户 [[email protected] test]# CAT/ETC/PASSWD | Wc-l34 If there is any mistake, please correct me! Thank you!
Text Processing command: Cut,sort,wc,uniq