April 24

8.10 Shell special symbol cut interception command

1. Shell special symbols

 

1 , * any arbitrary character (this is a wildcard)

2. ? Any character

3. #Comment character _

4. \ escape character

5 , | pipeline

2. Several commands related to the pipe character :

 2.1 Command to intercept a field: cut command      (-d -f is generally used together )

-d : followed by a delimiter character, the delimiter character should be enclosed in single quotes 

-f : followed by the first few blocks 

-c : the following is the first few characters 

 

-d is followed by a separator character, where a colon is used as the separator character , -f 1 is to intercept the first paragraph , and the space between -f and 1 is optional. 

-c can be followed by a number n , an interval n1-n2 , or multiple numbers n1, n2, n3 

blob.png 

cut split, -d separator   -f specifies the segment number    -c specifies the number of characters ,

cat passwd is a file, head only looks at the first two lines, cut -d intercepts the segmentation symbol as ':' , -f 1 means intercepts the first paragraph, 1,2 means the first two paragraphs, 1-3 means the first three paragraphs.

 8.11 sort_wc_uniq command

sort sort_wc count lines_uniq delete duplicate lines

1. sort sort, -n sort by numbers , -r reverse order   , -t separator , -kn1/-kn1,n2 ( basically rarely use -t)

-t is followed by a split character, which is the same as the cut -d option, what is the interception symbol; -n means to use pure numeric sorting, letters and special symbols are represented as 0 ; -r means reverse sorting; -u means to remove duplicates; - kn1, n2 means to sort from n1 range to n2 range, you can just write -kn1 , that is, sort the n1 field.   

1.1 Sort by sort as shown in the figure

blob.png 

1.2 Sort with pure numbers: sort -n 1.txt

blob.png 

1.3 Reverse order with pure numbers: srot -nr 1.txt

blob.png 

2.1 Command : wc 

Used to count the number of lines, characters, and words in a document. Common options are: 

-l : count the number of lines 

-m : count the number of characters 

-w : count the number of words 

blob.png 

wc does not follow any options, and directly follows the document, the number of lines, words, and characters will be output in turn

3.1 Command : uniq 

去重复的行,常与sort排序命令一起使用。使用uniq 的前提是需要先给文件排序,否则不管用

-c :统计重复的行数,并把行数写在前面 

blob.png 

 

8.12 tee_tr_split命令

1. 命令 : tee        ,选项 -a 追加

后跟文件名,类似与重定向 “>”, 但是比重定向多了一个功能,在把文件写入后面所跟的文件中的同时,还显示在屏幕上 

1.1 2.txt内容去除重后写入a.txt

blob.png 

1.2 tee -a 追加内容

blob.png 

2.tr 命令 替换字符,tr 'a' 'b',大小写替换tr '[a-z]' '[A-Z]'

blob.png 

3.split命令 切割文档 

常用选项: 

-b :依据大小来分割文档,单位为byte 

-l :依据行数来分割文档 

3.1 切割文档a.txt 每个为100K

blob.png 

3.2切割文档a.txt 每个为100K,文件命名开头为asd

blob.png 

3.3 切割文档a.txt 每个切割文档为1000

blob.png 

8.13 shell特殊符号下

 

1$ 变量前缀,!$组合(最近使用过的命令),正则里面表示行尾

blob.png 

2分号。多条命令写到一行,用分号分割

blob.png 

3 ~ 用户家目录,后面正则表达式表示匹配符

4& 放到命令后面,会把命令丢到后台

5、  > >> 2> 2>> &>

>    :正确重定向,会把之前的文件覆盖掉。

>>  :追加重定向,追加内容正确输出。

2>  :错误重定向

2>>:追加错误重定向

&>   : indicates correct and incorrect output redirection

 

6. [ ] specifies one of the characters, such as [ 0-9],[a-zA-Z],[abc]

7 , || and && , used between commands.

|| : means or , when using two commands at the same time, if the first command is unsuccessful, the second command is executed, and if the first command is successfully executed, the second command is not executed , an example is as follows:

blob.png 

&& : It means and means that when two commands are executed at the same time, if the previous command is successfully executed, the latter command will be executed, otherwise it will not be executed.

An example is as follows:

blob.png 

7.1 Determine whether a directory exists, such as: 

  [ -d aminglinux ] || mkdir aminglinux

(If the amolinux directory exists, the following command to create the directory will not be executed; if the amolinux directory does not exist, the command to create the directory will be executed)

experiment:

blob.png 

explain:

[ -d aminglinux ] : Determine if a directory exists.

 




Guess you like

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