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!

···

--
Posted via http://www.ruby-forum.com/.

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

···

On 4/9/08, Michele Zio <uncle.mike@email.it> wrote:

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

Michele Zio 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.

···

--
Posted via http://www.ruby-forum.com/\.

Adam Shelly wrote:

···

On 4/9/08, Michele Zio <uncle.mike@email.it> 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
--
Posted via http://www.ruby-forum.com/\.