I have a plain text table like this. I need to group the result line so that the data is together in their respective columns.
I can split the string (one line) on a space and then I will get an array like:
["2", "1/47", "M4044", "25:03*", "856", "12:22", "12:41", "17.52", "Some", "Name", "Yo", "Prairie", "Inn", "Harriers", "Runni", "25:03"]
I can also split on two spaces, which gets me close, but still inconsistent, as you see with the name:
["2", " 1/47", "M4044", " 25:03*", "856", " 12:22", " 12:41", "17.52 Some Name Yo", "", "", "", "", "", "", "Prairie Inn Harriers Runni", " 25:03 "]
I can specify which indexes to join on, but I need to grab possibly thousands of files just like this, and the columns are not always going to be in the same order.
The one constant is that the column data is never longer than the divider between column name and data (the ====). I tried to use this to my advantage, but found some loopholes.
I need to write an algorithm to detect what stays in the name column and what stays in whatever other ‘word’ columns. Any thoughts?
First we set up the problem:
I like to make a format string for String#unpack:
The rest is easy: