Delete first line of a text file

hi,
how can i delete first line of a file?

example:

file.txt:
1
2
3
4

after operation:

file.txt:
2
3
4

thanks!

On 4/9/08, Michele Z. [email protected] wrote:

hi,
how can i delete first line of a file?

Assuming it’s an ASCII file, this should work: (Although it might be
slow on very large files)

FILENAME=“file.txt”
text=‘’
File.open(FILENAME,“r”){|f|f.gets;text=f.read}
File.open(FILENAME,“w+”){|f| f.write(text)}

-Adam

Michele Z. wrote:

hi,
how can i delete first line of a file?

example:

file.txt:
1
2
3
4

after operation:

file.txt:
2
3
4

thanks!

File.readlines(“file.txt”)[0…-2]

-r.

Adam S. wrote:

On 4/9/08, Michele Z. [email protected] wrote:

hi,
how can i delete first line of a file?

Assuming it’s an ASCII file, this should work: (Although it might be
slow on very large files)

FILENAME=“file.txt”
text=‘’
File.open(FILENAME,“r”){|f|f.gets;text=f.read}
File.open(FILENAME,“w+”){|f| f.write(text)}

-Adam

it’s a very small file :slight_smile:
it works very well, thanks a lot!!!

michele