filename="/directory/Test1.txt"
set - A store
while IFS= read value
do
awk '{split($value,store," ")}'
done < "$filename"
echo ${#sore[@]}
From the code in the executing file, I would like each word in each line to be stored in an array. Later I would like the output to be printed out like below with more lines in the content, but each column of the line is limited to 3.
Subject Verb Adjective
Tom is hot
Jane is sweet
..............................................
I tried executing the code, but it seems that no value is stored into the array....I printed out the number of array in store and it shows 0....... How to split the string and append into the array?
declare -A store store2
eval read store[$(awk 'END {print "{1.." NR "},{1.." NF "}"}' $filename)] < <(fmt -1000 $filename)
for i in {1..2},{1..3}; do echo store[$i] = ${store[$i]}; done
If the number of columns is not constant for all lines
eval read store2[$(awk '{if(NF>max) max=NF} END {print "{1.." NR "},{1.." max "}"}' $filename)] < <(fmt -1000 $filename)
GNU bash, version 5.0.11(1)-release (x86_64-redhat-linux-gnu)