AWK reads the text line by line, and the command begins with a pattern-action statement: if the first field (word) equals the variable ‘a’, AWK does the action in brackets, namely print… But wait! No variable ‘a’ has been defined yet, so that action can’t happen on the first line. AWK moves to the second action, which is to set the variable ‘a’ equal to the contents of the last field/word ($NF) in the first line, and the variable ‘b’ to the contents of the whole first line ($0).
Get the Free Newsletter!
Subscribe to Developer Insider for top news, trends, & analysis