Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use loops in awk

Shulou Source: shulou.com Published: 2022-06-01 12:28:21 10月04日 Update

This article introduces the knowledge of "how to use loops in awk". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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-f BEGIN {# Loop through 1 to 10 iTunes 1; while (I

Tags: Loops commands expressions arrays functions variables files tests characters strings detection content more conditions entries knowledge simplicity indexing results parts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS Xiaomi vpn MySQL