The awk programming language allows us to use end blocks to provide [[finishoff?]] and [[cleanup?]] actions within the program.
An end block is marked with the END label:
END { # This is a begin block print "The end is here" # Print the closing message }
End blocks can are executed once only, after the last input record is read.
There is no default action for end blocks, so end block must contain defined actions. An end block must contain actions.
There is no current record information available within an end block, because end blocks are executed after the last input record has been read.
The original version of awk required the *end block* to be placed at the end of the program and only one end block was allowed. This is no longer a requirement of current awk versions, however it is recommended that this convention is observed for portability and readability purposes.
Multiple end blocks are executed in order in which they are defined.