Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15667 > unrolled thread

Re: Read last expression in a file?

Started byHeike Gramberg <heike.gramberg@gmail.com>
First post2011-01-31 08:23 +0000
Last post2011-02-03 10:29 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Read last expression in a file? Heike Gramberg <heike.gramberg@gmail.com> - 2011-01-31 08:23 +0000
    Re: Read last expression in a file? Chris Degnen <degnen@cwgsy.net> - 2011-02-02 11:14 +0000
      Re: Read last expression in a file? Chris Degnen <degnen@cwgsy.net> - 2011-02-02 12:03 +0000
        Re: Read last expression in a file? Albert Retey <awnl@gmx-topmail.de> - 2011-02-03 10:29 +0000

#15667 — Re: Read last expression in a file?

FromHeike Gramberg <heike.gramberg@gmail.com>
Date2011-01-31 08:23 +0000
SubjectRe: Read last expression in a file?
Message-ID<ii5rh6$ff3$1@smc.vnet.net>
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
>

[toc] | [next] | [standalone]


#15771

FromChris Degnen <degnen@cwgsy.net>
Date2011-02-02 11:14 +0000
Message-ID<iibea5$nul$1@smc.vnet.net>
In reply to#15667
You can find a Windows (XP) version of tail here: http://malektips.com/xp_dos_0001.html

(from the Windows Server 2003 Resource Kit Tools).

While 'tail outputfile' works on the command line, and the output
(last line -0) can be redirected to tail.txt like so:
tail -0 outputfile > tail.txt

the redirection doesn't seem to work when run from Mathematica. I.e.
using

Run["tail -0 outputfile > tail.txt];
Import["tail.txt]

I also tried your version: ReadList["!tail outputfile", Expression]
but no luck with that either.

Any suggestions, anyone?


On Jan 31, 8:23 am, Heike Gramberg <heike.gramb...@gmail.com> 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- Hide quoted text -
>
> - Show quoted text -

[toc] | [prev] | [next] | [standalone]


#15834

FromChris Degnen <degnen@cwgsy.net>
Date2011-02-02 12:03 +0000
Message-ID<iibh70$ol8$1@smc.vnet.net>
In reply to#15771
Actually this works fine:

Run["tail -0 outputfile > tail.txt"];
Import["tail.txt"]



On Feb 2, 11:14 am, Chris Degnen <deg...@cwgsy.net> wrote:
> You can find a Windows (XP) version of tail here:http://malektips.com/xp_=
dos_0001.html
>
> (from the Windows Server 2003 Resource Kit Tools).
>
> While 'tail outputfile' works on the command line, and the output
> (last line -0) can be redirected to tail.txt like so:
> tail -0 outputfile > tail.txt
>
> the redirection doesn't seem to work when run from Mathematica. I.e.
> using
>
> Run["tail -0 outputfile > tail.txt];
> Import["tail.txt]
>
> I also tried your version: ReadList["!tail outputfile", Expression]
> but no luck with that either.
>
> Any suggestions, anyone?
>
> On Jan 31, 8:23 am, Heike Gramberg <heike.gramb...@gmail.com> 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 th=
e 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 outpu=
t
> > > as the new input.   However, I can't find a way to only read the la=
st
> > > 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- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

[toc] | [prev] | [next] | [standalone]


#15915

FromAlbert Retey <awnl@gmx-topmail.de>
Date2011-02-03 10:29 +0000
Message-ID<iie01f$bjq$1@smc.vnet.net>
In reply to#15834
Hi,
>>
>> Run["tail -0 outputfile > tail.txt];
>> Import["tail.txt]
>>
>> I also tried your version: ReadList["!tail outputfile", Expression]
>> but no luck with that either.
>>
>> Any suggestions, anyone?
>>

I've seen you have a version that works, but if you are interested in a
version which doesn't create an intermediate file here is something that
also works for me on Windows (with tail installed from the Resource Kit
Tools):

Import["!tail -0 \"" <> fname <> "\"", "Text"]

my filename did contain spaces, so I needed the enclosing "". Actually
to see what goes wrong it is useful to redirect stderr to stdout, so you
can see error messages, like here:

Import["!tail -0 \"" <> fname <> "\" 2>&1", "Text"]

once you have the command line running, you can of course also use
ReadList directly to perform the conversion to Mathematica expressions:

ReadList["!tail -0 \"" <> fname <> "\"", Expression]

hth,

albert

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web