4 ms·
You can also put a similar code block at the start of a general processing entry. This applies on both flat (uniform record) and hierarchical (multiple record-
by dredmorbius 5y ago
You can also put a similar code block at the start of a general processing entry. This applies on both flat (uniform record) and hierarchical (multiple record-type) data.
E.g.:
{
name = $1
dob = $2
grade = $3
# ...
# Do stuff with name / dob / grade, etc.
}
If the data are structured, so that there are multiple record types (typically defined by prefix or some other regex) you can put variable assignments within each block.
/^rectype1/ { var1 = $1; var2 = $2, ... }
/^rectype2/ { varA = $1; varB = $2, ... }
I prefer to leave BEGIN blocks for defining constants or tables and such.
- ketanmaheshwari 5y agoI prefer using colname = n (as opposed to colname = $n) so I can use $colname so as to distinguish the column names from local variables.