2018-4-24

8.10 Shell special symbol cut command

8.11 sort_wc_uniq command

8.12 tee_tr_split command

8.13 Under special shell symbols



8.10 Shell special symbol cut command

Summarize special symbols

image.png

Examples of \ escape characters:

image.png



image.png

cut cuts a string. Example: Use the pipe character head to find out the first two paragraphs, and then do an interception.

image.png










8.11 sort_wc_uniq command

sort sort (usually used in conjunction with uniq)

image.png

sort /etc/passwd The normal first line is root and now it is displayed in the order of abc. (sorted by Asma by default)


          head /etc/passwd >>1.txt

          vim1.txt, add a few more lines of numbers and special symbols, and then sort 1.txt

         image.png

 Special symbols come first, then numbers, then letters.


sort -n (to sort by numbers, letters or special symbols will be regarded as zeros in front.)

image.png


sort -r (sort in reverse)

sort -t (specify the delimiter, just understand it)


wc -l counts the number of lines -m counts the number of characters (newlines are also counted) -w counts the words (one word, separated by spaces)


uniq (de-duplication is conditional. It needs to be sorted first and then de-duplicated, otherwise it will be invalid)

uniq -c count the number of repetitions // basically used in combination with sort, sort first and then deduplicate sort 1.txt|uniq

(commands like sort and uniq do not change the content)








8.12 tee_tr_split command

tee like > (output redirection)

比如sort 2.txt |uniq -c |tee a.txt 

The role of |tee is to redirect, and the redirected content will be displayed below (> the content will not be displayed)

tee -a like >> (append)


tr (replace)

image.png

And you can specify the range [az] into [AZ] is to turn all letters into uppercase.


split is used to view some large files, such as very large logs.

split -b specifies the size

split -l specifies the number of lines

It is possible to specify a name while cutting, but it is only a prefix. split -l 100k a.txt aaa








8.13 Under special shell symbols

image.png


$! indicates the end of the previous line

;For writing multiple commands in one line;Split


&>: Both true and false output redirection.



|| means or for example ls 1.txt || ls 2.txt (if the first item is unsuccessful, the second item will be executed, and if the first item is successful, the second item will not be executed)

&& The next command will only be executed if the previous command is executed successfully.



Guess you like

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