Gawk variables: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
= Assignment = | = Assignment = | ||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="awk"> | ||
integer = 1; | integer = 1; | ||
float = 1.1; | float = 1.1; | ||
Line 21: | Line 21: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Assignment --> | </blockquote><!-- Assignment --> | ||
= Assignment Operators = | |||
<blockquote> | |||
<syntaxhighlight lang="awk"> | |||
var+= 1; | |||
</syntaxhighlight> | |||
</blockquote><!-- Assignment Operators --> |
Revision as of 01:30, 19 July 2021
Arguments
Arguments are named like in bash,
$1
for the first,$2
for the second, etc.
$0
refers to the entire line.echo "foo" "bar" | awk 'BEGIN { print $1 $2 }' # foobar awk -f file.awk "foo" "bar" # akw scripts
Assignment
integer = 1; float = 1.1; string = "abc"; array[1] = "abc"; result = ( (1/100) * 20 );
Assignment Operators
var+= 1;