gawk: Allowing trailing data
1
1 4.6.3 Capturing Optional Trailing Data
1 --------------------------------------
1
1 There are times when fixed-width data may be followed by additional data
1 that has no fixed length. Such data may or may not be present, but if
1 it is, it should be possible to get at it from an 'awk' program.
1
1 Starting with version 4.2, in order to provide a way to say "anything
1 else in the record after the defined fields," 'gawk' allows you to add a
1 final '*' character to the value of 'FIELDWIDTHS'. There can only be
1 one such character, and it must be the final non-whitespace character in
1 'FIELDWIDTHS'. For example:
1
1 $ cat fw.awk Show the program
1 -| BEGIN { FIELDWIDTHS = "2 2 *" }
1 -| { print NF, $1, $2, $3 }
1 $ cat fw.in Show sample input
1 -| 1234abcdefghi
1 $ gawk -f fw.awk fw.in Run the program
1 -| 3 12 34 abcdefghi
1