Hi,
I am trying to populate an array with data from a text file. I have a working method using awk but it is too slow and inefficent. See below.
The text file has 70,000 lines. As awk is a line editor it reads each line of the file until it gets to the required line and then processes it. Then for the next loop it starts at the first line and then reads each line of the file until it gets to the required line and then processes it. This is very inefficent when you get towards the bottom of a large file.
A want to efficently write the 70,000 lines of a text file into an array where the each line of the file contains 5 numbers and is comma seperated. The array index should be equal to the first number. The value of the array for each index can be equal to either the whole line or the last four numbers of the line.
The method does not have to use awk, so long as it is a bash script.
I can't figure out how to use awk to read the data to the array as it reads through the file on the first read through.
for ((i=1; i<=70000; i++)) do
line_num=$i
ARRAY_3D_ELSET[$i]=$(awk -F, -v var="$line_num" 'NR==var {print $0}' 3D_ELSET.tmp)
done