Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use loops in awk

Shulou Source: shulou.com Published: 2022-06-01 17:36:53 10月04日 Update

This article mainly introduces how to use loops in awk. It is very detailed and has a certain reference value. Friends who are interested must finish it!

The awk script has three main parts: the BEGIN and END functions (both optional), and the functions that the user writes to execute each time. To some extent, the body of the awk is a loop because the commands in the function are executed once for each record. However, sometimes you want to execute multiple commands on a single record, so you need to use a loop.

There are many types of loops that are suitable for different scenarios.

While cycle

A while loop detects an expression and executes the command if the expression is true. When the expression changes to false, the loop breaks.

#! / bin/awk-fBEGIN {# Loop through 1 to 10 iTunes 1; while (I

Tags: Loops commands expressions variables arrays functions files articles tests characters strings detections content data text conditions entries simplicity indexes results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia vpn Redmi MySQL