Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Variables/AWK/variables-1.awk
Normal file
20
Task/Variables/AWK/variables-1.awk
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
BEGIN {
|
||||
# Variables are dynamically typecast, and do not need declaration prior to use:
|
||||
fruit = "banana" # create a variable, and fill it with a string
|
||||
a = 1 # create a variable, and fill it with a numeric value
|
||||
a = "apple" # re-use the above variable for a string
|
||||
print a, fruit
|
||||
|
||||
# Multiple assignments are possible from within a single statement:
|
||||
x = y = z = 3
|
||||
print "x,y,z:", x,y,z
|
||||
|
||||
# "dynamically typecast" means the content of a variable is used
|
||||
# as needed by the current operation, e.g. for a calculation:
|
||||
a = "1"
|
||||
b = "2banana"
|
||||
c = "3*4"
|
||||
|
||||
print "a,b,c=",a,b,c, "c+0=", c+0, 0+c
|
||||
print "a+b=", a+b, "b+c=", b+c
|
||||
}
|
||||
7
Task/Variables/AWK/variables-2.awk
Normal file
7
Task/Variables/AWK/variables-2.awk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# usage: awk -v x=9 -f test.awk
|
||||
BEGIN {
|
||||
y = 3
|
||||
z = x+y
|
||||
print "x,y,z:", x,y,z
|
||||
printf( "x=%d,y=%d,z=%d:", x,y,z )
|
||||
}
|
||||
15
Task/Variables/AWK/variables-3.awk
Normal file
15
Task/Variables/AWK/variables-3.awk
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function foo(s, k) {
|
||||
# s is an argument passed from caller
|
||||
# k is a dummy not passed by caller, but because it is
|
||||
# in the argument list, it will have a scope local to the function
|
||||
k = length(s)
|
||||
print "'" s "' contains", k, "characters"
|
||||
}
|
||||
BEGIN {
|
||||
k = 42
|
||||
s = "Test"
|
||||
foo("Demo")
|
||||
print "k is still", k
|
||||
foo(s,k)
|
||||
print "k still is", k
|
||||
}
|
||||
2
Task/Variables/AWK/variables-4.awk
Normal file
2
Task/Variables/AWK/variables-4.awk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Feeding standard-input with echo:
|
||||
echo -e "2 apples 0.44$ \n 3 banana 0.33$" | awk '{p=$1*$NF; sum+=p; print $2,":",p; }; END{print "Sum=",sum}'
|
||||
Loading…
Add table
Add a link
Reference in a new issue