MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Read last expression in a file?

  • To: mathgroup at
  • Subject: [mg116111] Re: Read last expression in a file?
  • From: Eric Loots <eric.loots at>
  • Date: Wed, 2 Feb 2011 06:09:51 -0500 (EST)

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]


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

  • Prev by Date: Re: Mathematica 8 Home Edition
  • Next by Date: Re: some demonstrations no longer work right in version 8
  • Previous by thread: Re: DesignerUnits 2011-01-08 for Mathematica 8, 7, 6
  • Next by thread: Re: Read last expression in a file?