Open text file in Numbers when it is space delimited, but some fields are strings in quotes with spaces

numbers

I have a log file I'd like to open in Numbers to make sifting through it a lot easier. The problem is that the format isn't CSV. Each line has about a dozen fields, and the fields themselves are separated by spaces. However, some of those fields are strings, which contain space, so I can't just do a find replace for spaces and put the comma in. One field, the date, is actually formatted like this: [06/Feb/2018:03:27:37 +0000]. This appears to be the only spot where []s are used, so I could find/replace those with "s, but I'm still having trouble importing the document. It places every row in a single column.

So, to summarize, my goal is to take an input file and break up each row so that the space is the delimiter, but it ignores spaces within quotes.

Best Answer

if you have an editor that can use regex (for example textwrangler or bbedit)
or you are willing to use sed (in this case remember the -E flag)
or you can write a small filter in any language you know (for example perl or python),
you can first change the brackets into "s and then use the regex:
s/\ (?=(?:[^"]"[^"]")[^"]$)/\t/g
to convert any space not between quotes into tabs, so that Numbers will import it correctly (it's not that I am this good with regexes, it is explained here: regex101.com/r/sU3fA2/29)