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!
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
4after operation:
file.txt:
2
3
4thanks!
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
it works very well, thanks a lot!!!
michele
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs