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.48.
(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.49.
(In Script)
    {exit(1) }

(The Command Line)
% echo $status  (csh, tcsh)
    1

$ echo $? (bash, sh, ksh, tcsh)
    1

Explanation

An exit status of zero indicates success, and an exit value of nonzero indicates failure (a convention in UNIX/Linux). It is up to the programmer to provide the exit status in a program. The exit value returned in this example is 1.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.93.141