ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Idea - Return *new* lines from a text file (w/ example)

<< < (3/5) > >>

strictlyfocused02:
Could you:

1) use a "tail" utility to save the last n lines
2) when you want to check what's changed, use "tail" again to save the new tail
3) use a "diff" utility to see the difference?

The UnxUtils project on SourceForge contains command-line versions of both "tail" and "diff."
-rjbull (July 08, 2010, 03:39 PM)
--- End quote ---

I suppose this could make this work, but it will definitely end up convoluted. I would probably have to tail the last 500 lines twice and then diff them which would really suck if only 2 lines have been added.  Even worse if more than 500 lines have been written a lot of info could get overlooked.

Even if someone more familiar with AutoHotkey were able to pinpoint where the function I posted is flawed that would be fine.

rjbull:
Haven't go anything more helpful to add  :(  I was expecting to set it up with a batch file that would save the end of old log, save the end of new log, diff, then delete the old tail and rename the new tail as the old tail.  But, I agree that you wouldn't know where to cut the tail from.  I assumed you'd have to use tail because diff wouldn't be able to cope with files that were in use and constantly added to.  If you could find a diff that coped with log files that were presumably locked, you could use it directly.

I don't know if ExamDiff Pro, the visual diff I use, can do this, but I can't see it in the Help file.  Maybe one of the others can, like Beyond Compare, the favourite on DC?

steeladept:
What about something simple like this:

1) Read backward through log file looking for EOF (whatever delimiter you define as the end of file)
2) Display out lines after last EOF.
3) Write new EOF at end.

Note that this should not be the standard EOF but rather some special symbol (string?) that won't ever be written in normal log files.  Maybe something in a foreign language with alternating case or something.  Whatever it is, make it its own line entry written by the parser to designate the end of the last file and read only from there forward.

Just my logic, coding it could be much worse.

markcramer:
Most tail implementations I've seen can also show just the last N bytes.

So save the current file size, then when you want to display the difference, subtract the old size from the current one and display just that count of bytes using tail?

If you need to roll the log file, just reset the saved size to 0.

Is there any reason this won't work?

CmputrAce:
1. The calling script is written in what language?
2. Do you want a command-line app that just returns the new test to stdout (CON:)?

I have a few thoughts... if I can write a function that you can embed in your script, then keeping the file size between calls is much easier. If I write a quick DOS program to do this, then I'd build it this way:
if you call the program with only the file name, I will return the file size to you. If you call the program with the file name AND the file size, I will return the new file size, a newline, then the text beginning at the character+1 position you submitted as the second parameter to the call.

This should be pretty easy, IMO.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version