Lesson 24 Shell special symbols and cut_sort_wc_uniq_tee_tr_split command

1. Special symbols

'*' Wildcard, any character
'?' Any character
'#' Comment character
'\' Escape character
'|' Pipe
'$' Variable prefix
'!$' Combination, which means the end
';' more Write each command to one, separate the
'~' user's home directory with a semicolon, and put the regular expression
'&' after the command, the command will be thrown into the background
'>' Correct redirect
'>>' Append Redirect
'2>' Error redirect
'2>>' Error follow redirect
'&>' Put error and correct redirect in the same file as one of
the specified characters in '[ ]', [0-9] [az ]
'||' means or in the shell. If the first command is executed successfully, the subsequent commands will no longer be executed
'&&' If the previous command is executed successfully, the latter command will be executed

2. Several commands related to the pipe character

cut command: intercept string,

Example: cat /etc/passwd |head -2 |cut -d ":" -f 1,2(1-10)
-d specifies the separator:
-f which paragraph
-c specifies the number of characters Example: cat / etc/passwd |head -2 |cat -c 4

sort command: sort

Example: sort -nr filename
-n Arrange in numbers, letters will be considered as 0
-r Sort in reverse order
-t delimiter

wc -l command: count the number of lines

wc -m command: count the number of characters
wc -w count words
(cat -A filename can view all hidden characters in the text)

uniq deduplicate command:

(It is convenient to use the sort command with the uniq command)
-c count the number of repetitions

tee redirects while still showing on the screen

Similar to >, for
example: sort 1.txt |uniq -c |tee a.txt

tr replace character

tr 'a''b', case replacement: tr '[az]' '[AZ]'
Example: change a string from lowercase to uppercase
echo "haohaoxuexi" |tr '[ha]' '[HA]'

split cut

-b size (default unit), for example: split -b 100M filename custom prefix name
-l number of lines Example: split -l 1000 filename

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324804903&siteId=291194637