I could, but the bit that's got me stumped is working out the 'parent' number for each line.
I've been thinking about it more and I'm going to try using an array to keep a record of the 'id' number for the last line with [x] number of tabs.
Then just go through the file line by line and the 'parent' number should be the 'id' of the last line with 1 less tab at the front.
I'll give it a go and report back!