Homework One: awk, the collation of variables
awk Syntax:
-F defines the field delimiter, and the default delimiter is a contiguous space or tab
Use the order of $1,$2,$3 to represent the different fields of each row in files separated by the interval symbol
NF variable indicates the number of fields in the current record
The NR variable represents the number of rows that awk reads in
-V Define variables and assign values can also be borrowed from the shell variable to introduce
Variable:
1. System Variables
Set: Show All variables
ENV: Environment variables
2. Assignment variables
Varname=value
Echo $VARNAME
Delete variable unset VARNAME
3. Common system Variables
PATH, PWD, LANG, HOME, Histsize, PS1, IFS
4. Global variables and local variables
[Email protected] ~]# gender= ' Male ' #在爹这个位置定义一个局部变量gender
[Email protected] ~]# export money=1000 #在爹这个位置定义一个全局变量money
[Email protected] ~]# bash #切换到子bash
[[email protected] ~]# echo $gender #在儿子这里看它爹的局部变量gender, results are empty, not seen
[[email protected] ~]# echo $money #在儿子这里看它爹的全局变量money, you can see 1000
[Email protected] ~]# export hobby= ' Piao ' #在儿子这里定义一个全局变量hobby
[[Email protected] ~]# exit #退出, go into Dad's bash environment
[Email protected] ~]# echo $hobby #爹是看不到儿子的export的, son's son can see
Job Two: awk text processing
Print user names for UID within the 30~40 range
Print the line number and user name of the 第5-10 line
Print odd lines
Print even rows
Print a row with a number of fields greater than 5
Print uid Not equal to GID username
Print a user without a shell specified
Job Three: Shell scripting
Automatic deployment, initial configuration, and startup of Nginx reverse proxy service
Automatic deployment, initial configuration, and launch of three web
Monitoring script: Monitor the memory usage of each machine >70%, then output alarm information
(Idea Tip:
[Email protected] ~]# ((80>70))
[[email protected] ~]# echo $?
0
)
Day10.awk command and scripting of the shell