|
shouldn't it be "*a"? CheckUsing *a produced the same results, I remember trying multiple ways due to my google searching. If one is correct and the other is not, that is one thing I was hoping to learn from this little experiment :)
http://www.lua.org/manual/5.1/manual.html#pdf-file:read ...
Also, you can try to print the length of the string with
print(#logstring).
Couple of things:
1) How big is your log file? Are you trying to read too much? You may want to read line-by-line with "*line" instead of "*all", though it is more inefficient.
2) Here's a recent snippet I used:
local file = io.open(feed,"r")
while true dolocal line = file:read("*l")
if line == nil then break end
text = line .. "\n" .. textend
What's the format of the log file, exactly? In particular, what charset is it using (range and encoding), and what newline format? A hex dump of (the start of) the file can be very helpful in guessing that, if it's not documented somewhere. You mention "notepad", so I might guess that you're on Windows, which increases the probability that the file is some variant of UTF16, possibly UTF-16LE with a BOM (byte order mark). But that's a wild guess, and not likely to be right.On Tue, Oct 7, 2008 at 7:26 PM, Brian Sanders <brian.sanders@gmail.com> wrote:
Hello, I am new to LUA and was trying to do some basic scripts to get a feel for it. I have tried to make a basic script to parse through a log file and display simple output. I have the following code which I thought I understood just fine.
print ("opening file for reading")
logfile = io.open("system.log","r")
logstring = logfile:read("*all")
print(logstring)
What is confusing me is, I can create a new text document, and just type a few words in it. Then I can use this script (unless in my many variations I posted the wrong one) and get the text back out. If I could get past this, I would then do some small matching off the log file. Unfortunately it only works when I make my text document. When I grab the actual log file I am trying to parse, it only returns a space, a square, and then the first character in the file. When opening this log file in word pad it does look normal with line returns after each log entry. In notepad however the line returns are shown as squares. I am therefore led to believe this must have something to do with formatting of this file, but I really don't know. Can anyone point me in the right direction here? I just don't see how these line returns could be the problem when it does not even parse that far, it just gets to the first character.
Thanks for helping a new guy out,
Brian
Unfortunately the simple term "text file" covers a whole family of formats.
-- James