Re: Using Lua to combine CSV files
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Using Lua to combine CSV files
- From: Shmuel Zeigerman <shmuz@...>
- Date: 2007年6月26日 08:46:40 +0200
The following is a straightforward solution (not optimized for
performance).
local timestamp1, timestamp2, first, last, outlogfile = ...
timestamp1, timestamp2 = tonumber(timestamp1), tonumber(timestamp2)
local fout = assert (io.open (outlogfile, "w"))
local done
for i = first, last do
if done then break end
local filename = "logfile" .. i .. ".csv"
for line in io.lines(filename) do
local timestamp = tonumber (line:match ("^[^,]+"))
if timestamp then
if timestamp >= timestamp1 then
if timestamp <= timestamp2 then fout:write (line, "\n")
else done = true break
end
end
else
error ("record with bad timestamp in file " .. filename)
end
end
end
fout:close()
--
Shmuel