7.8. Program Control Statements

7.8.1. next Statement

The next statement gets the next line of input from the input file, restarting execution at the top of the awk script.

Example 7.47.
(In Script)
{ if ($1 ~ /Peter/){next}
    else {print}
}

EXPLANATION

If the first field contains Peter, awk skips over this line and gets the next line from the input file. The script resumes execution at the beginning.

7.8.2. exit Statement

The exit statement is used to terminate the awk program. It stops processing records, but does not skip over an END statement. If the exit statement is given a value between 0 and 255 as an argument (exit 1), this value can be printed at the command line to indicate success or failure by typing:

Example 7.48.
 (In Script) ...

Get UNIX® Shells by Example, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.