Hi all.
Well, I have the next code:
I need to make an array with the values I have in the bucle, but just don't get it...
Question is, how can I store in an array that values, and how can I display them with echo?
Hi all.
Well, I have the next code:
I need to make an array with the values I have in the bucle, but just don't get it...
Question is, how can I store in an array that values, and how can I display them with echo?
Still working in it, but dont get to save the values
awk -F: '{
for(i=1; i<=NF; i++)
b=$i
}' tmpid
OR
awk -F: '{
split($0, b, FS)
}' tmpid
There are a lot of threads regarding this item, search for arrays awk.
Regards
vgersh99,
I tried that before, but when I write echo ${b[1]} then I get a blank.
Why this happen?
Franklin52,
I'll be more careful from now on. Sorry.
'echo' is a shell command. 'b' is your awk array.
awk -F: '{
for(i=1; i<=NF; i++)
b=$i
for(j=1; j<=i; j++)
printf("j->[%d] b[%d]->[%s]\n", j, j, b[j])
}' tmpid
vgersh99,
Im new in the unix world. So now I understand what you told me before.
So, the variables I set within awk, can't be used in shell later?
I mean, I created an array named "b" with "x" elements. That variable is exclusive within awk, isn't it?
partially correct - see below.
correct.
Look at this piece of code:
#!/bin/ksh
file='tmpid'
typeset -i i=0
while read input
do
IFS=:; set -A arr ${input}
while (( i < ${#arr[@]} ))
do
echo "arr[$i]=${arr[$i]}"
i=$(( $ + 1 ))
done
((i=0))
done < "${file}"
and also here:
#!/bin/ksh
a='one:two::four'
IFS=':' ;set -A arr ${a}
len=${#arr[@]}
typeset -i i=0
while (( i < len ))
do
echo "arr[$i] ==> ${arr[$i]}"
i=$(( $i + 1 ))
done
As suggested, use the Search function of these forums to find related threads.
Many thanks, you've provided me a great help.
Next question I have, I will search for it first.
Again, many thanks for the tips.