当前位置:网站首页>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
边栏推荐
- 秋招将临 如何准备算法面试、回答算法面试题
- 资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
- Li Kou ----- the maximum profit of operating Ferris wheel
- DataGrid directly edits and saves "design defects"
- 1.2 download and installation of the help software rstudio
- 力扣------经营摩天轮的最大利润
- Feng Tang's "spring breeze is not as good as you" digital collection, logged into xirang on July 8!
- Poj3414广泛搜索
- Detailed explanation of memset() function usage
- MMAP learning
猜你喜欢
Huawei fast game failed to call the login interface, and returned error code -1
Drawing HSV color wheel with MATLAB
面试官:并发编程实战会吗?(线程控制操作详解)
递归查询多级菜单数据
How can Huawei online match improve the success rate of player matching
Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
Incentive mechanism of Ethereum eth
Reading and writing operations of easyexcel
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
uni-app 蓝牙通信
随机推荐
Golang (1) | from environmental preparation to quick start
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
初级软件测试必问面试题
HDU 4391 paint the wall segment tree (water
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
让开发效率提升的跨端方案
854. 相似度为 K 的字符串 BFS
Parker驱动器维修COMPAX控制器维修CPX0200H
力扣------经营摩天轮的最大利润
Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
Exercise 1 simple training of R language drawing
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
Deployment of Jenkins under win7
深信服X计划-网络协议基础 DNS
Selenium gets the verification code image in DOM
1.2 download and installation of the help software rstudio
Analysis and test of ModbusRTU communication protocol
ESP32