gawk: Fields with fixed data
1
1 4.6.4 Field Values With Fixed-Width Data
1 ----------------------------------------
1
1 So far, so good. But what happens if there isn't as much data as there
1 should be based on the contents of 'FIELDWIDTHS'? Or, what happens if
1 there is more data than expected?
1
1 For many years, what happens in these cases was not well defined.
1 Starting with version 4.2, the rules are as follows:
1
1 Enough data for some fields
1 For example, if 'FIELDWIDTHS' is set to '"2 3 4"' and the input
1 record is 'aabbb'. In this case, 'NF' is set to two.
1
1 Not enough data for a field
1 For example, if 'FIELDWIDTHS' is set to '"2 3 4"' and the input
1 record is 'aab'. In this case, 'NF' is set to two and '$2' has the
1 value '"b"'. The idea is that even though there aren't as many
1 characters as were expected, there are some, so the data should be
1 made available to the program.
1
1 Too much data
1 For example, if 'FIELDWIDTHS' is set to '"2 3 4"' and the input
1 record is 'aabbbccccddd'. In this case, 'NF' is set to three and
1 the extra characters ('ddd') are ignored. If you want 'gawk' to
1 capture the extra characters, supply a final '*' in the value of
1 'FIELDWIDTHS'.
1
1 Too much data, but with '*' supplied
1 For example, if 'FIELDWIDTHS' is set to '"2 3 4 *"' and the input
1 record is 'aabbbccccddd'. In this case, 'NF' is set to four, and
1 '$4' has the value '"ddd"'.
1