hello all,
currently i am attempting to create an array in awk using a flat file as the source. the flat file format is as such:
word1 word2 word3
so i am attempting to use the NF awk parameter in order to assign values to the elements in the array. unfortunately this is not working just yet.
here is the code i currently have:
export x=0
delim=`awk '{print NF}' array_source.out`
export delim
echo $delim "is the value of the delimiter"
until (( x == delim ))
do
echo $x "is the pre math value for counter"
test[x]=`awk "BEGIN{ y = "$x" } NF == y { print $1 }" array_source.out`
x=`expr $x + 1`
echo $test[x]
echo $x "is the post math value for counter"
# echo $test[cnt1]
done
I am attempting to use NF to control which field is shoved into the array. By using a delimiter equal to NF in the source file that should control the loop as its delimiter.
However for some reason I cant get the array populated.
What am I missing here? I used this logic to create an array based on NR but this is new since it is a single line source file and I am using NF as a controller.
Any help would be GREAT! Tx!
currently i am attempting to create an array in awk using a flat file as the source. the flat file format is as such:
word1 word2 word3
so i am attempting to use the NF awk parameter in order to assign values to the elements in the array. unfortunately this is not working just yet.
here is the code i currently have:
export x=0
delim=`awk '{print NF}' array_source.out`
export delim
echo $delim "is the value of the delimiter"
until (( x == delim ))
do
echo $x "is the pre math value for counter"
test[x]=`awk "BEGIN{ y = "$x" } NF == y { print $1 }" array_source.out`
x=`expr $x + 1`
echo $test[x]
echo $x "is the post math value for counter"
# echo $test[cnt1]
done
I am attempting to use NF to control which field is shoved into the array. By using a delimiter equal to NF in the source file that should control the loop as its delimiter.
However for some reason I cant get the array populated.
What am I missing here? I used this logic to create an array based on NR but this is new since it is a single line source file and I am using NF as a controller.
Any help would be GREAT! Tx!