This is a custom scripts to recursively filter records similar to an index on a CSV. Though the script, then filters down to a series of results that do have the matching result.

Mechanism

This is pretty basic, with a couple of functions doing the heavy lift.

First the code, creates a map of the find key and recursive results that match that key. This is admittedly inefficient, but been done for cases where the key does not exist as the first available value. will think about a better algo to make this more efficient.

The matching key is being bled into an array, which is then used to filter out the map.

The final results are then set into a 2x2 array and printed into a CSV.

Visualization

Scenario: Find all values that the key which has Value C has and present.

Column 0
Imagine this is our key
Column 1
Imagine this is our value
Column 2Column 3
Keys 1Value AOther Data 1Other Data 2
Keys 2Value BOther Data 1Other Data 2
Keys 3Value C «Other Data 1Other Data 2
Keys 1Value AOther Data 1Other Data 2
Keys 2Value DOther Data 1Other Data 2
Keys 3Value A «Other Data 1Other Data 2
Keys 4Value C ««Other Data 1Other Data 2

Here, the two keys that have Value C are Keys 3 and Keys 4
Keys 3 has another value Value A, while Keys 4 has no other values

This would result in the following output

KeyValue1Value2
Keys 3Value CValue A
Keys 4Value C

Learnings

How do I transpose the CSV?
How do we split out the reading of the file, without entering an infinite loop this should be easy, and just needs some thought