[Date Index] [Thread Index] [Author Index]
Re: Read last expression in a file?
Great tip Heike. Building further on this: To get just the last line: ReadList["!tail -1 someFile", String] Also, on unix systems, you can use pipes to get more flexibility: Get the second last line only: ReadList["!tail -2 someFile | head -1", String] Or exactly the 4th line: ReadList["!head -4 /Users/eloots/Desktop/t | tail -1", String] Eric On 31 Jan 2011, at 09:22, Heike Gramberg wrote: > If you are working on unix/linux/os x and your output file contains one expression per line, you could use something like > > ReadList["!tail outputfile", Expression] > > where outputfile is the name of your output file. This basically calls the external command tail which is a program on unix/linux that displays the last few lines of a file. > > I'm not familiar with windows so I don't what the windows equivalent of tail would be. > > Heike. > > On 30 Jan 2011, at 00:43, Ramiro wrote: > >> Hello, >> >> I wrote a program that generates a lot of Mathematica output. >> >> Now I need to restart it using the very last expression of such output >> as the new input. However, I can't find a way to only read the last >> expression in a file, something like a Read that would start at the >> end. It would be too time consuming and perhaps not enough memory in >> my computer to read the entire file. >> >> Any suggestions? >> >> Thanks, >> Ramiro >>