当前位置:网站首页>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
边栏推荐
- How can Huawei online match improve the success rate of player matching
- EBS Oracle 11g 克隆步骤(单节点)
- MMAP学习
- MMAP learning
- matlab绘制hsv色轮图
- Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture
- 他们主动布局(autolayout)环境的图像编辑器
- Huawei fast game failed to call the login interface, and returned error code -1
- Poj 3237 Tree (Tree Chain Split)
- Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
猜你喜欢
SQL knowledge leak detection
2.2.3 output of documents
ICMP 介绍
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
MMAP学习
Defect detection - Halcon surface scratch detection
Cross end solution to improve development efficiency rapidly
Scenario interview: ten questions and ten answers about distributed locks
Comprehensive optimization of event R & D workflow | Erda version 2.2 comes as "7"
2022-07-03-cka- latest feedback from fans
随机推荐
xlrd常见操作
Four components of logger
JMeter installation under win7
Selenium finds the contents of B or P Tags
如何组织一场实战攻防演练
How to prepare for the algorithm interview and answer the algorithm interview questions
秋招将临 如何准备算法面试、回答算法面试题
Teach yourself to train pytorch model to Caffe (2)
Making global exception handling classes with aspect
"Grain mall" -- Summary and induction
int GetMonth( ) const throw( );后面的throw( )什么意思?
Opérations de lecture et d'écriture pour easyexcel
MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
Alibaba cloud award winning experience: build a highly available system with polardb-x
力扣------经营摩天轮的最大利润
Image editor for their AutoLayout environment
Parker驱动器维修COMPAX控制器维修CPX0200H
R language learning notes
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
HYSBZ 2243 染色 (树链拆分)