I have a tool that outputs timestamped information. I am trying to create a script that invokes multiple instances of the tool and outputs sorted information. The idea is:
for id in "${ids[@]}"
do
my_tool ${id} > ${id} &
outputs[${id}]= # first line of ${id} file
done
while [[ $(still_running) ]]
do
# find the index of minimum timestamp in the outputs array
echo ${outputs[$index]}
outputs[${index}]= # read in next line of file ${index}
done
However, I am not sure how to implement the file reading. I know how to read a file line-by-line, but this requires keeping it open. I could open multiple files and keep them open but I don't know how to do that without manually creating variables for them.
I think it is possible to do this if somehow we keep track of which line each file is up to, but I don't know how to read a specific line from a file in bash.
For example, I want to be able to do something like
var1=$(read file1 line1)
var2=$(read file2 line1)
var3=$(read file3 line1)
var1=$(read file1 line2)
var1=$(read file1 line3)
var3=$(read file3 line2)
...