lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi all,
Thanks for accepting me!
When I'm reading a long text file with LUA, Can I use pagination for splitting output?

Here the code:

function file_exists(file)
  local f =, "rb")
  if f then f:close() end
  return f ~= nil

function lines_from(file)
  if not file_exists(file) then return {} end
  lines = {}
  for line in io.lines(file) do 
    lines[#lines + 1] = line
  return lines

local file = 'test.lua'
local lines = lines_from(file)

for k,v in pairs(lines) do
  print('line[' .. k .. ']', v)

I Linux command:
$ cat filename | more

Thanks for all