Jump to content




Tail for ComputerCraft


  • You cannot reply to this topic
3 replies to this topic

#1 kornichen

  • Members
  • 220 posts
  • LocationGermany

Posted 04 January 2015 - 09:35 AM

Hello,

when using linux I often fall back on using tail which is a program that comes with linux. It is not completely done yet, so you can't use every parameter of tail, you can use on linux or unix but the most important parameters are already implemented.

Wikipedia describes it like this:

Quote

tail is a program on Unix and Unix-like systems used to display the tail end of a text file or piped data.

Download:
Pastebin: 976V0Fhs
pastebin get 976V0Fhs tail

Usage:
tail [OPTION] FILE
Already implemented parameters:
-n N - Output of the last N lines instead of the default 10
-f - Output of the attached data if the file grows
Examples of usage:
tail
tail testfile
tail -n 25 testfile
tail -f testfile
tail -nf 5 testfile
tail -fn 5 testfile
The first line prints out a list of all parameters.
The second line prints out the last 10 lines of testfile
The third line prints out the last 25 lines of testfile
The fourth line prints out the last 10 lines of testfile and every lines that gets attached to testfile. Cancel with CTRL+T.
The fifth and the sixth line do exactly the same. The only difference is that the parameters are swapped around. Both lines print out the last 5 lines of testfile and wait for new lines to be attached to testfile to print them out.

Edited by kornichen, 04 January 2015 - 09:36 AM.


#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 04 January 2015 - 10:38 AM

This is pretty useful. Just a couple of things:
  • Locals! Everything really should be a local variable
  • Follow currently uses sleep calls in an infinite loop, maybe you could link in to fs.write (and the close/flush methods) to implement a file system watcher with events instead.


#3 kornichen

  • Members
  • 220 posts
  • LocationGermany

Posted 04 January 2015 - 12:20 PM

View PostSquidDev, on 04 January 2015 - 10:38 AM, said:

This is pretty useful. Just a couple of things:
  • Locals! Everything really should be a local variable
  • Follow currently uses sleep calls in an infinite loop, maybe you could link in to fs.write (and the close/flush methods) to implement a file system watcher with events instead.

I know it is better to use local variables but I always tend not to use them. I will change it, don't worry ;)
And I will take a deeper look at the fs API to solve this little problem.

#4 doublequestionmark

  • Members
  • 118 posts
  • LocationI honestly don't know

Posted 05 January 2015 - 03:24 AM

This Is Great, I always wanted tail in computercraft.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users