Logic Machine Forum
Best way to parse a txt table - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Best way to parse a txt table (/showthread.php?tid=1663)



Best way to parse a txt table - gtsamis - 19.10.2018

Hi, 

I have a near by weather station that publish it's data as a txt table. http://grhost.info/kastelokampos/downld02.txt

I would like to get the only the last line of the table in order to use it in my project.
Currently i am using sting.sub (total length - 205 which is the line length) to get the last line and then again string.sub to get each value.

I am sure there must be a more delicate/robust solution but i am stuck so any help would be appreciated.

Thank you in advance
George


RE: Best way to parse a txt table - admin - 22.10.2018

Use this code to split last line data into a table:
Code:
data = ... -- get remote data

lines = data:split('\n')
line = lines[ #lines - 1 ] -- last line
line = line:gsub('%s+', ' ') -- remove multiple spaces
line = line:trim()
line = line:split(' ') -- convert to table

log(line)



RE: Best way to parse a txt table - gtsamis - 22.10.2018

(22.10.2018, 06:21)admin Wrote: Use this code to split last line data into a table:
Code:
data = ... -- get remote data

lines = data:split('\n')
line = lines[ #lines - 1 ] -- last line
line = line:gsub('%s+', ' ') -- remove multiple spaces
line = line:trim()
line = line:split(' ') -- convert to table

log(line)

Nice and clean, thank you!  Smile