Whne I tried as below code, no is giving the 0 value and for that resion not getting any value from array. Please help me on this...
OUTPUT like :
0
After spliting
but not getting array elements...
no = split(TempArr, Temp);
print no;
print "After spliting";
for(i in Temp)
{
print Temp;
}
Please show your full code. if TempArr is awk variable, and not empty then it should work, before using split , put this print TempArr and check, whether variable is empty or not, if its prints nothing then what you are getting "0" is right. since variable has nothing to split.
$ cat test.ksh
#!/bin/ksh
# some value
ID="1 2 3 4 5 6 7"
# Array
set -A IDARR $ID
# Echo array contents...
echo "From shell ${IDARR[*]}"
# Execute awk script
awk -f test.awk -v TempArr="${IDARR[*]}"
$ cat test.awk
BEGIN {
# this is variable
print "from awk", TempArr;
# split variable contents into array with default FS space
split(TempArr,NewArray)
# print contents of NewArray we created above..
for(i in NewArray)
{
print "index",i,"element",NewArray;
}
}
Resulting
$ ksh test.ksh
From shell 1 2 3 4 5 6 7
from awk 1 2 3 4 5 6 7
index 4 element 4
index 5 element 5
index 6 element 6
index 7 element 7
index 1 element 1
index 2 element 2
index 3 element 3
From terminal if you want to execute awk script try like this
$ awk -f test.awk -v TempArr="Hai hello world this is test"
Resulting
from awk Hai hello world this is test
index 4 element this
index 5 element is
index 6 element test
index 1 element Hai
index 2 element hello
index 3 element world