当前位置:网站首页>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
边栏推荐
- snipaste 方便的截图软件,可以复制在屏幕上
- Parallel shift does not provide any acceleration - C #
- go-zero微服务实战系列(九、极致优化秒杀性能)
- DM8 database recovery based on point in time
- Conversion of yolov5 XML dataset to VOC dataset
- How to choose solid state hard disk and mechanical hard disk in computer
- awk从入门到入土(12)awk也可以写脚本,替代shell
- How to set multiple selecteditems on a list box- c#
- string. Format without decimal places will generate unexpected rounding - C #
- Four essential material websites for we media people to help you easily create popular models
猜你喜欢
FOC控制
转:优秀的管理者,关注的不是错误,而是优势
manjaro安装微信
How can we make a monthly income of more than 10000? We media people with low income come and have a look
Sequence model
Comparison between sentinel and hystrix
Newh3c - routing protocol (RIP, OSPF)
Getting started with microservices: gateway gateway
Conversion of yolov5 XML dataset to VOC dataset
DM8 command line installation and database creation
随机推荐
NewH3C——ACL
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
DM8 database recovery based on point in time
2022 electrician (intermediate) examination question bank and electrician (intermediate) examination questions and analysis
awk从入门到入土(14)awk输出重定向
Unity text superscript square representation +text judge whether the text is empty
SQL statement view SQL Server 2005 version number
awk从入门到入土(12)awk也可以写脚本,替代shell
awk从入门到入土(7)条件语句
转:优秀的管理者,关注的不是错误,而是优势
Unity write word
ctfshow web255 web 256 web257
Li Kou today's question -1200 Minimum absolute difference
Codeforces Round #803 (Div. 2)(A-D)
FRP intranet penetration, reverse proxy
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
Use Alibaba cloud NPM image acceleration
What should I do if there is a problem with the graphics card screen on the computer
System disk expansion in virtual machine
How to play dapr without kubernetes?