manpagez: man pages & more
info gawk
Home | html | info | man

File: gawk.info,  Node: Allowing trailing data,  Next: Fields with fixed data,  Prev: Skipping intervening,  Up: Constant Size

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 fw.in                          Show sample input
     -| 1234abcdefghi
     $ gawk -f fw.awk fw.in               Run the program
     -| 3 12 34 abcdefghi

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.