gawk: Viewing And Changing Data
14.3.3 Viewing and Changing Data
--------------------------------
The commands for viewing and changing variables inside of 'gawk' are:
'display' [VAR | '$'N]
Add variable VAR (or field '$N') to the display list. The value of
the variable or field is displayed each time the program stops.
Each variable added to the list is identified by a unique number:
gawk> display x
-| 10: x = 1
This displays the assigned item number, the variable name, and its
current value. If the display variable refers to a function
parameter, it is silently deleted from the list as soon as the
execution reaches a context where no such variable of the given
name exists. Without argument, 'display' displays the current
values of items on the list.
'eval "AWK STATEMENTS"'
Evaluate AWK STATEMENTS in the context of the running program. You
can do anything that an 'awk' program would do: assign values to
variables, call functions, and so on.
'eval' PARAM, ...
AWK STATEMENTS
'end'
This form of 'eval' is similar, but it allows you to define "local
variables" that exist in the context of the AWK STATEMENTS, instead
of using variables or function parameters defined by the program.
'print' VAR1[',' VAR2 ...]
'p' VAR1[',' VAR2 ...]
Print the value of a 'gawk' variable or field. Fields must be
referenced by constants:
gawk> print $3
This prints the third field in the input record (if the specified
field does not exist, it prints 'Null field'). A variable can be
an array element, with the subscripts being constant string values.
To print the contents of an array, prefix the name of the array
with the '@' symbol:
gawk> print @a
This prints the indices and the corresponding values for all
elements in the array 'a'.
'printf' FORMAT [',' ARG ...]
Print formatted text. The FORMAT may include escape sequences,
such as '\n' (Escape Sequences). No newline is printed
unless one is specified.
'set' VAR'='VALUE
Assign a constant (number or string) value to an 'awk' variable or
field. String values must be enclosed between double quotes
('"'...'"').
You can also set special 'awk' variables, such as 'FS', 'NF', 'NR',
and so on.
'watch' VAR | '$'N ['"EXPRESSION"']
'w' VAR | '$'N ['"EXPRESSION"']
Add variable VAR (or field '$N') to the watch list. The debugger
then stops whenever the value of the variable or field changes.
Each watched item is assigned a number that can be used to delete
it from the watch list using the 'unwatch' command.
With a watchpoint, you may also supply a condition. This is an
'awk' expression (enclosed in double quotes) that the debugger
evaluates whenever the watchpoint is reached. If the condition is
true, then the debugger stops execution and prompts for a command.
Otherwise, 'gawk' continues executing the program.
'undisplay' [N]
Remove item number N (or all items, if no argument) from the
automatic display list.
'unwatch' [N]
Remove item number N (or all items, if no argument) from the watch
list.