 <p>This will definitely do the task for you.</p> <pre><code>tTable = {} OldIDX, OldIDX2, bSwitched, bSwitched2 = 0, 0, false, false for str in io.lines("txt.txt") do local _, _, iDx, iDex, sIdx, sVal = str:find( "^%| ([%d|%s]?) %| ([%d|%s]?) %| (%S?) %| (%S?) %|$" ) if not tonumber(iDx) then iDx, bSwitched = OldIDX, true end if not tonumber(iDex) then iDex, bSwitched2 = OldIDX2, true end OldIDX, OldIDX2 = iDx, iDex if not bSwitched then tTable[iDx] = {} end if not bSwitched2 then tTable[iDx][iDex] = {} end bSwitched, bSwitched2 = false, false tTable[iDx][iDex][sIdx] = sVal end </code></pre> <h1>NOTE</h1> <p>The only thing you can change in the code is the name of the file. :)</p> <h1>EDIT</h1> <p>Seems like I was wrong, you did need some changes. Made them too.</p>