Every awk program consists of a 1 or more blocks of
LOGICAL-EXPRESSION { ACTIONS }
If LOGICAL-EXPRESSION is evaluated for each input line and if it equates to true (or it wasn't specified) the ACTIONS block is executed for that line.
(Special LEs of BEGIN (and END) execute their ACTION block once before (or after) the file is processed, this program dosn't use BEGIN or END)
If ACTIONS block is missing the default action is applied, which is print the current line buffer.
In this program we have 1 action block without a LE (so it executes for every line) and after that we have an LE of 1 (true) with no ACTION so it prints every line buffer. We modify the value of field 1 in the 1st action block and this printe in the 2nd.
Breakdown of code as follows:
Code | Description |
-F, | Field seperator as comma |
$1= | Replace value of first field with... |
NR>1?X:Y | if record # greater than 1 then X else Y |
"amr,"$1",dummy,10" | X: arm, + 1st field + ,dummy,10 |
"region,"$1",key,value" | Y: region, + 1st field + ,key,value |
1 | 1 is true, default action is print record (with updated 1st field), using OFS specified below |
OFS=, | Output field sepeartor is comma |