From: Alex Gutteridge Date: 2007-09-27T13:31:15+09:00 Subject: Re: some file operations On 27 Sep 2007, at 12:23, blufur wrote: > how can my ruby program tell me how many lines are in a text file? IO.foreach iterates over the lines in a file which you can then count, or IO.read reads the whole thing into a string from which you can then count the number of lines. > how can i have my ruby program edit the last line of a text file > (not add another line at the end, but get and then change the line > at the end). Easiest (IMO) is to read the whole file, edit the last line and write back out. E.g: lines = IO.read('file').split lines[-1] = 'edit' puts lines > Thanks for any suggestions! Alex Gutteridge Bioinformatics Center Kyoto University