Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20130326a

Last N lines

During the Operating Systems lab you may have heard about the "tail" command. This command can print the last N lines of a text file. For instance, "tail -10 file.txt" prints the last 10 lines of the given file.

Exercise

Write a script that works similarly to the Unix "tail" command. How to use it:

./my_tail.py -10 input.txt

Version (B)

In order to practice OO programming, solve the exercise with a class. How to use it:

...
tail = Tail(<input_file>, <N>)
tail.print_result()

Where "print_result()" will print the last N lines of the the given input file.

Bonus point: if solved correctly, you can get +1 point.


I want to see a non-trivial solution! That is, I won't accept if you count the number of lines and then skip (number_of_lines - N) lines. I won't accept either if you read the whole content of the file to the memory. Find a different approach…

Tip: http://www.smartsmarina.com/product_photos/superior1.jpg, s/o/e/

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2017 August 04, 11:58