Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove number of bytes from beginning of file

Tags:

python

file

I want to copy a file without the first 256 bytes.

Is there a nice way to do it in python?

I guessing that the simple way is to read byte-byte with a counter and then start copy only when it get to 256.

I was hoping for more elegant way.

Thanks.

like image 206
ZoRo Avatar asked Aug 27 '13 12:08

ZoRo


People also ask

How do I remove the first few bytes of a file?

To delete the first few bytes, you can either overwrite them, or you have to rewrite and re-align the whole file. Something like dd can do this fairly efficiently.

How do I remove the last byte from a file?

Using the truncate Command. The command truncate contracts or expands a file to a given size. The truncate command with option -s -1 reduces the size of the file by one by removing the last character s from the end of the file. The command truncate takes very little time, even for processing large files.

What is dd command Linux?

dd is a command-line utility for Unix and Unix-like operating systems whose primary purpose is to convert and copy files. On Unix, device drivers for hardware (such as hard disk drives) and special device files (such as /dev/zero and /dev/random) appear in the file system just like normal files.


1 Answers

with open('input', 'rb') as in_file:
    with open('output', 'wb') as out_file:
        out_file.write(in_file.read()[256:])
like image 181
FogleBird Avatar answered Oct 01 '22 22:10

FogleBird