The commands for viewing and changing variables inside of gawk are:
display
[var | $
n]$
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:
dgawk> display x -| 10: x = 1
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"
eval
param, ...end
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 ...]dgawk> 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 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 ...]set
var=
value"..."
).
You can also set special awk variables, such as FS
,
NF
, NR
, etc.
watch
var | $
n ["
expression"
]w
var | $
n ["
expression"
]$
n) to the watch list.
dgawk then stops whenever
the value of the variable or field changes. Each watched item is assigned a
number which 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 dgawk evaluates whenever the watchpoint is reached. If the condition is true, then dgawk stops execution and prompts for a command. Otherwise, dgawk continues executing the program.
undisplay
[n]unwatch
[n]