Next: , Previous: , Up: Constant Size   [Contents][Index]

4.6.3 Capturing Optional Trailing Data

There are times when fixed-width data may be followed by additional data that has no fixed length. Such data may or may not be present, but if it is, it should be possible to get at it from an awk program.

Starting with version 4.2, in order to provide a way to say “anything else in the record after the defined fields,” gawk allows you to add a final ‘*’ character to the value of FIELDWIDTHS. There can only be one such character, and it must be the final non-whitespace character in FIELDWIDTHS. For example:

$ cat fw.awk                         Show the program
-| BEGIN { FIELDWIDTHS = "2 2 *" }
-| { print NF, $1, $2, $3 }
$ cat                          Show sample input
-| 1234abcdefghi
$ gawk -f fw.awk               Run the program
-| 3 12 34 abcdefghi