Maybe the OP should have posted their attempt at the solution and further detailed their requirements.
is it a static file or one that may be updated during the task.
That may have focused the solution.
BTW, I Love the variants and the kick around of the pluses and minuses of each
Just my $0.02