| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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: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,
displaydisplays 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
awkprogram would do: assign values to variables, call functions, and so on.-
evalparam, … - awk statements
-
end This form of
evalis 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.-
printvar1[,var2 …] -
pvar1[,var2 …] Print the value of a
gawkvariable or field. Fields must be referenced by constants: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.-
printfformat [,arg …] Print formatted text. The format may include escape sequences, such as ‘\n’ (see section Escape Sequences). No newline is printed unless one is specified.
-
setvar=value Assign a constant (number or string) value to an
awkvariable or field. String values must be enclosed between double quotes ("…").You can also set special
awkvariables, such asFS,NF,NR, etc.-
watchvar |$n ["expression"] -
wvar |$n ["expression"] Add variable var (or field
$n) to the watch list.dgawkthen 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 theunwatchcommand.With a watchpoint, you may also supply a condition. This is an
awkexpression (enclosed in double quotes) thatdgawkevaluates whenever the watchpoint is reached. If the condition is true, thendgawkstops execution and prompts for a command. Otherwise,dgawkcontinues 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
