Hi, I have a fairly lengthy awk program I am writing for my personal media server.(unraid)
The awk program is contained completely within a BEGIN{} and is run as a part of a web interface.
I need a loop writen in awk for within BEGIN{} that will take each line from an input file and store it in an array.
line 1 goes into array[1], line 2 into array[2]... etc.
so something like this.... although this did not work
I have never used awk before this program. what am i doing wrong and how do i fix it?
Please help,
Matt
The awk program is contained completely within a BEGIN{} and is run as a part of a web interface.
I need a loop writen in awk for within BEGIN{} that will take each line from an input file and store it in an array.
line 1 goes into array[1], line 2 into array[2]... etc.
so something like this.... although this did not work
Code:
BEGIN {
#stuff
#Read lines in file
file_to_read = "/file/location"
cc = 0
while (( getline line < file_to_read ) > 0 ) {
# just in case written in windows
gsub("\r","", line)
# store line in array
array[cc] = line
cc++;
}
close(file_to_read);
#more stuff
}
I have never used awk before this program. what am i doing wrong and how do i fix it?
Please help,
Matt