[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: New to LUA, trying to read from a file
- From: "James Dennett" <james.dennett@...>
- Date: Tue, 7 Oct 2008 19:46:33 -0700
On Tue, Oct 7, 2008 at 7:26 PM, Brian Sanders <firstname.lastname@example.org>
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")
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,
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.
Unfortunately the simple term "text file" covers a whole family of formats.