4

How to truncate x bytes of the head file ? I have a log which has 5 GB and I want to cut first 3 GB ( remove old information) .

sweet_sugar
  • 1,390
  • 3
  • 13
  • 22
  • possible duplicate of [How to delete parts of a file in python?](http://stackoverflow.com/questions/4692065/how-to-delete-parts-of-a-file-in-python) – Mikael Ohlson Apr 29 '15 at 08:34

1 Answers1

4

Use the seek method:

fname = 'bigfile.log'
fid = open(fname, "rb")
fid.seek(3 * (2 ** 30) , 0) # go to the ~(3*10^9)th Byte, with respect to the start
Buffer = fid.read(2 * (2 ** 30))

Click here for more information.

dobkind
  • 416
  • 4
  • 10