当前位置:网站首页>Awk from entry to earth (7) conditional statements
Awk from entry to earth (7) conditional statements
2022-07-04 08:46:00 【Wonderful binary】
Just like the actual programming language ,AWK It also provides the execution flow of conditional statement control program . In this chapter, we will introduce AWK How to use conditional statements in .
IF sentence
Conditional statements test conditions, and then select and execute corresponding actions according to the conditions . The following is the syntax of conditional statements :
if (condition)
action
Curly braces can also be used to perform a set of operations :
if (condition)
{
action-1
action-1
.
.
action-n
}
The following example determines whether the number is odd or even :
$ awk 'BEGIN {num = 10; if (num % 2 == 0) printf "%d is even number.\n", num }'
Execute the above command to get the following result :
10 is even number.
IF - ELSE sentence
if-else Statement allows another set of actions to be performed when the condition is false . The following is if-else The grammar of :
if (condition)
action-1
else
action-2
among , When the condition is true action-1, Execute if condition is false action-2. Here is an example of using this statement to determine whether a number is even :
$ awk 'BEGIN {num = 11;
if (num % 2 == 0) printf "%d is even number.\n", num;
else printf "%d is odd number.\n", num
}'
The following results can be obtained by performing the above operation :
11 is odd number.
if-else-if
We can easily use multiple if-else Sentence construction if-else-if So as to realize the judgment of multiple conditions . Examples are as follows :
$ awk 'BEGIN {
a=30;
if (a==10)
print "a = 10";
else if (a == 20)
print "a = 20";
else if (a == 30)
print "a = 30";
}'
Execute the above command to get the following result :
a = 30
边栏推荐
- awk从入土到入门(10)awk内置函数
- System disk expansion in virtual machine
- Codeforces Round #803 (Div. 2)(A-D)
- The upper layer route cannot Ping the lower layer route
- Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
- HMS core helps baby bus show high-quality children's digital content to global developers
- Ehrlich sieve + Euler sieve + interval sieve
- Fault analysis | MySQL: unique key constraint failure
- Question 49: how to quickly determine the impact of IO latency on MySQL performance
- Basic discipline formula and unit conversion
猜你喜欢

一文了解数据异常值检测方法

ctfshow web255 web 256 web257

Unity text superscript square representation +text judge whether the text is empty

Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14

Codeforces Round #793 (Div. 2)(A-D)

go-zero微服务实战系列(九、极致优化秒杀性能)

09 softmax regression + loss function

Developers really review CSDN question and answer function, and there are many improvements~

微服務入門:Gateway網關

Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid
随机推荐
How to pass custom object via intent in kotlin
DM database password policy and login restriction settings
How to choose solid state hard disk and mechanical hard disk in computer
How to re enable local connection when the network of laptop is disabled
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,Gauss-Jordan消去法,源代码
Redis 哨兵机制
ArcGIS application (XXII) ArcMap loading lidar Las format data
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
From scratch, use Jenkins to build and publish pipeline pipeline project
Webapi interview question summary 01
Group programming ladder race - exercise set l1-006 continuity factor
awk从入门到入土(15)awk执行外部命令
Flutter 集成 amap_flutter_location
FOC控制
The upper layer route cannot Ping the lower layer route
Learn nuxt js
yolov5 xml数据集转换为VOC数据集
User login function: simple but difficult
Const string inside function - C #