Awk control statement
The break and continue statements can use the break statement to exit the loop when a specific condition is true. When a specific condition is true, the continue statement skips the continue statement, switches the statement back to the top of the loop, and starts the next loop.
Example
$ awk '{for(x = 3; x <= NF; x++){if($x < 0){ print "Bottomed out!"; break}/*break out of for loop*/}}' filename
Note: If the value of field $ x is less than 0, the break statement will control the statement that jumps to the right curly braces of the loop body, that is, the loop jumps out.
$ awk '{for(x = 3; x <= NF; x++){if($x < 0){ print "Bottomed out!"; continue}/*starts next iteration of the for loop*/}}' filename
Note: If the value of the field $ x is equal to 0, the continue statement converts the control back to the top of the loop and starts execution, starting with the 3rd expressions x ++ of the for loop.
Next statement
The next statement extracts the next line of input from the input file, and then re-runs from the top of the awk script.
Example
Awk '{
If ($1 ~ /Peter/) {next}
Else {print}
} 'Filename'
Note: If the first field of a row contains Peter, awk skips the row, reads the next line from the input file, and then executes the script from the beginning.
Exit statement
The exit statement is used to terminate the awk program. It can only interrupt the processing of records and cannot skip the END statement. If the exit statement parameter is a value (exit 1) between 0 and, the value is printed on the command line to indicate whether the program is successfully executed, and indicates the type of failure.
Example
$ Awk '{exit 1}' filename
$ Echo $?
1
Note: If the exit status is 0, the operation is successful. If the exit status is not 0, the operation fails (this is a unified convention of Linux ). The exit status is determined by the programmer whether the service is provided in the program. In this example, the exit status returned by the command is 1.