Hello friends,
I have a problem in printing an array..
Example if my array line contains 4 elements like following
line[1]=0002 , line[2]=202200, line[3]=200002, line[4]= 300313
Now
one = sprintf line[1] line[2] line[3] line[4]
will concatenate my whole array to one.
But I am not sure about the array index how long will it will be ..If more big array came I need to write it again like
one = sprintf line[1] line[2] line[3] line[4] line[5] .....
Please help me with a logic or code .. how to loop here instead of using index explicitly..
Thanks in advance..
awk 'BEGIN{a[1]="abc";a[2]="def";print length(a)}'
2
Once you know the number of elements, you can use a for loop.
Thanks for the reply ,, Yes I do know how many elements are in the array,
but my problem is to print it in one variable
suppose if my number of elements in the array is 3 ,then my commnad should look like this
input = sprint line[1] line[2] line[3]
On the other hand if the number of array element increases suppose to 4 then my command should look like
input = sprint line[1] line[2] line[3] line[4]
and like wise you can see the sprint line is varying with the index number..
That is my basic need .. pls help..
awk 'BEGIN {
line[1]="a"
line[2]="b"
line[3]="c"
for ( i=1;i<=3;i++) {
result=result""line
}
print result
}'
Thank you I got that.. Many many thanks ..
Thanks I did like this
input = ""
for (i=1 ; i < j ; i ++){
input = sprint input "" line
}
no need : input=""
what is sprint?
input = input "" line [i]should suffice.
I guess sprint to print to a variable GHOSTDOG.. Am I right ?
Thanks ..