当前位置:网站首页>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
边栏推荐
- Newh3c - routing protocol (RIP, OSPF)
- MySQL relearn 1-centos install mysql5.7
- Manjaro install wechat
- AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
- SQL statement view SQL Server 2005 version number
- Cancel ctrl+alt+delete when starting up
- Internal learning
- 力扣今日题-1200. 最小绝对差
- [untitled] 2022 polymerization process analysis and polymerization process simulation examination
- awk从入门到入土(7)条件语句
猜你喜欢

Call Baidu map to display the current position

How college students choose suitable computers

manjaro安装微信

AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human

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

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

ArcGIS application (XXII) ArcMap loading lidar Las format data

AcWing 244. Enigmatic cow (tree array + binary search)

High order phase difference such as smear caused by myopic surgery

DM8 tablespace backup and recovery
随机推荐
DM8 tablespace backup and recovery
High order phase difference such as smear caused by myopic surgery
Difference between static method and non static method (advantages / disadvantages)
Démarrage des microservices: passerelle
Sports [running 01] a programmer's half horse challenge: preparation before running + adjustment during running + recovery after running (experience sharing)
Ehrlich sieve + Euler sieve + interval sieve
Fault analysis | MySQL: unique key constraint failure
OpenFeign 服务接口调用
What if I forget the router password
SQL statement view SQL Server 2005 version number
awk从入门到入土(4)用户自定义变量
awk从入门到入土(14)awk输出重定向
埃氏筛+欧拉筛+区间筛
es6总结
Flutter integrated amap_ flutter_ location
微服務入門:Gateway網關
The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)
awk从入门到入土(18)gawk线上手册
How can we make a monthly income of more than 10000? We media people with low income come and have a look
System disk expansion in virtual machine