comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Write to a certain line of a file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Write to a certain line of a file [message #78964] Wed, 18 January 2012 11:49 Go to next message
Zhang Bo is currently offline  Zhang Bo
Messages: 22
Registered: October 2011
Junior Member
Is there a way open a file and go to the nth line and change the
content of this line, left the rest of file intact.
Re: Write to a certain line of a file [message #79046 is a reply to message #78964] Fri, 20 January 2012 08:52 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 1/20/12 9:26 AM, David Fanning wrote:
> Mark Piper writes:
>
>> Ah, nuts! Yeah, I understand. I guess it's moot anyway because, as David
>> has shown, it's trivial to read/replace/rewrite a text file.
>
> Well, it wasn't as trivial as I might have led you to
> believe yesterday. For some reason, I left the part out
> of my example where I actually wrote the *strings* back
> into the file! So, instead of taking 0.014 seconds to
> write a 10000 line file, it actually took something like
> 0.033 seconds. Still *mostly* trivial. ;-)

Only not trivial if you are doing it a lot, in which case I would cache
the results in memory and only write periodically.

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL, A Guide to Learning IDL: http://modernidl.idldev.com
Research Mathematician
Tech-X Corporation
Re: Write to a certain line of a file [message #79047 is a reply to message #78964] Fri, 20 January 2012 08:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark Piper writes:

> Ah, nuts! Yeah, I understand. I guess it's moot anyway because, as David
> has shown, it's trivial to read/replace/rewrite a text file.

Well, it wasn't as trivial as I might have led you to
believe yesterday. For some reason, I left the part out
of my example where I actually wrote the *strings* back
into the file! So, instead of taking 0.014 seconds to
write a 10000 line file, it actually took something like
0.033 seconds. Still *mostly* trivial. ;-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Write to a certain line of a file
Next Topic: IDLVM and execute

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:58:04 PDT 2025

Total time taken to generate the page: 0.21500 seconds