awk-04-流程控制




if

格式:
if ( 条件 ) 语句 [ else 语句 ]

单分支

image-20210817110139284


正则匹配判断

image-20210817110159111


双分支

image-20210817110219637

多分支

image-20210817110236303




while

格式
while (条件) 语句

awk是按行处理的,每次读取一行,并遍历打印每个字段

image-20210817110350235

image-20210817112017831




for

for语句C语言风格

![image-20210817110418912](/Users/lichengguo/Library/Application Support/typora-user-images/image-20210817110418912.png)


不换行倒序打印

image-20210817110511917


for语句遍历数组

image-20210817110531367


break和continue语句

break跳出当前循环

continue跳过当前循环

image-20210817110558298


删除数组

delete array 删除数组

delete array[index] 删除数组元素

image-20210817110617225

数组元素的键和值存储在 awk 程序内部的一个表中,该表采用散列算法,因此数组元素是随机排序


exit语句

exit退出程序,与shell的exit一样

image-20210817110645305


posted @ 2021-08-17 11:25  李成果  阅读(36)  评论(0编辑  收藏  举报