当前位置:网站首页>Shell script, awk uses if, for process control
Shell script, awk uses if, for process control
2022-07-05 21:46:00 【Excellent dengzonglei】
Shell Script ,awk Process control , Support for,if etc.
One 、 Single branch if Judge
1、awk ‘{ Instructions }’ dir
awk -F: ‘BEGIN{x=0} {if($3>=1000){i++}}END{print i}’ /etc/passwd
In the statistical file uid Greater than or equal to 1000 Quantity of content .
2、awk -F: ‘{if($1==“root”){print $1,$3}}’ /etc/passwd
awk The style is similar to the programming language , Constants use double quotation marks , You can't use single quotes or backquotes
Two 、 Multiple branches if Judge
1、 Double branch if…else
awk -F: ‘{if($3>=1000){i++}else{j++}} END{print i,j}’ /etc/passwd
Judge uid1000 The number of users and 1000 The number of users below
2、 Multiple branches ,if…else if…else
awk -F: ‘{if($30){print $1}else if($31000){print $1}else{print $7}}’ /etc/passwd
3、 ... and 、for loop ,awk Of for use c The grammatical format of a language
awk ‘BEGIN{for(i=1;i<=5;++i){print i}}{print}’ /etc/passwd
Print numbers before printing user information 1-5
Four 、awk Arrays and Applications
1、 Define an array
Format : Array name [ Subscript ]= Element value
awk ‘BEGIN{name[0]=“TOM”;name[1]=“JERRY”;print name[0],name[1]}’
Be careful print The following variables are used , Separate , Will print separately with spaces on the same line , If you use a semicolon and write two print, Two lines of content will be printed separately .
2、 Call array
Array name [ Subscript ]
3、 Traversal array
for( Variable name in Array name ){print Array name [ Variable ]}
The definition of an array cannot be name=“1234”,print name[1], This is used in awk There are grammatical errors in
Example :
1、awk ‘BEGIN{name[0]=“TOM”;name[1]=“JERRY”;print name[0],name[1]}’
Print... On the screen TOM,JERRY
2、awk ‘{array[$1]++}END{for(i in array){print i,array[i]}}’ dir
Print the number of repetitions of the contents of the first column in the specified file
边栏推荐
- Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
- 思特奇加入openGauss开源社区,共同推动数据库产业生态发展
- Advantages of robot framework
- Cross end solutions to improve development efficiency
- Summary of El and JSTL precautions
- Postgres establish connection and delete records
- Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
- Uni app Bluetooth communication
- 123456
- Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
猜你喜欢
随机推荐
Oracle检查点队列–实例崩溃恢复原理剖析
Codeforces 12D Ball 树形阵列模拟3排序元素
Making global exception handling classes with aspect
Robot operation mechanism
poj 3237 Tree(树链拆分)
深信服X计划-网络协议基础 DNS
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
matlab绘制hsv色轮图
SQL common syntax records
怎么利用Tensorflow2进行猫狗分类识别
What should I do to prepare for the interview algorithm position during school recruitment?
事项研发工作流全面优化|Erda 2.2 版本如“七”而至
How can Huawei online match improve the success rate of player matching
one hundred and twenty-three thousand four hundred and fifty-six
SecureCRT使用提示
POJ 3237 tree (tree chain splitting)
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
Deeply convinced plan X - network protocol basic DNS
ICMP 介绍
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)