Gawk variables: Difference between revisions

From wikinotes
(Created page with "= Arguments = <blockquote> Arguments are named like in bash, <code>$1</code> for the first, <code>$2</code> for the second, etc.<br> <code>$0</code> refers to the entire line....")
 
No edit summary
Line 10: Line 10:
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Arguments -->
</blockquote><!-- Arguments -->
= Assignment =
<blockquote>
<syntaxhighlight lang="bash">
integer = 1;
float = 1.1;
string = "abc";
array[1] = "abc";
result = ( (1/100) * 20 );
</syntaxhighlight>
</blockquote><!-- Assignment -->

Revision as of 01:19, 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 );