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

Home » Public Forums » archive » Modify txt 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
Modify txt file [message #85039] Wed, 26 June 2013 00:43 Go to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
Hi,
I've pretty much read text files pretty often, but haven't manage to modify a text file in a fast way...
Here is the thing. Consider a text file like this:
parameter1 = 5
parameter3 = 2
parameter2 = 8
parameter7 = 23

I would like to change a line 3 to:
parameter2 = 9

Is there a quick way to do this? At the moment I'm reading the file and storing it in an string array, modifying the selected string and rewriting the whole file. Alternatively, I could write in parallel to another file and then do renaming. But I thought that there should be a smarter way using OPENU, but this way I insert a line and not substitute it... or?

Regards,
Helder
Re: Modify txt file [message #85042 is a reply to message #85039] Wed, 26 June 2013 06:55 Go to previous messageGo to next message
Bill Nel is currently offline  Bill Nel
Messages: 31
Registered: October 2010
Member
You can do this with point_lun. You have to keep track of the file offset to your line 3 as your write the original file. And the string you're substituting has to have exactly the same number of bytes as the original. I've done it (to fill in a fixed length text field with a value that isn't known until more of the file is written), but I don't recommend it as a general technique.
Re: Modify txt file [message #85043 is a reply to message #85039] Wed, 26 June 2013 07:19 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Helder writes:

> I've pretty much read text files pretty often, but haven't manage to modify a text file in a fast way...
> Here is the thing. Consider a text file like this:
> parameter1 = 5
> parameter3 = 2
> parameter2 = 8
> parameter7 = 23
>
> I would like to change a line 3 to:
> parameter2 = 9
>
> Is there a quick way to do this?

Do you find this slow? This is the way I've always done it with
configuration files. It has never seemed slow to me.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Modify txt file [message #85053 is a reply to message #85043] Wed, 26 June 2013 13:43 Go to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Wednesday, June 26, 2013 4:19:16 PM UTC+2, David Fanning wrote:
> Helder writes:
>
>
>
>> I've pretty much read text files pretty often, but haven't manage to modify a text file in a fast way...
>
>> Here is the thing. Consider a text file like this:
>
>> parameter1 = 5
>
>> parameter3 = 2
>
>> parameter2 = 8
>
>> parameter7 = 23
>
>>
>
>> I would like to change a line 3 to:
>
>> parameter2 = 9
>
>>
>
>> Is there a quick way to do this?
>
>
>
> Do you find this slow? This is the way I've always done it with
>
> configuration files. It has never seemed slow to me.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Hi, thanks for the answers.
In my example I used numbers and that is not actually the only thing I'm dealing with. Some of the fields refer to directories and these change (in length) all the time.
David: I don't find it slow, but sometimes I have the feeling I'm making things more complicated and "you" guys have better ways...
Thanks anyhow... now I feel like I'm doing the right thing :-)

Cheers,
Helder
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 8.2.2 direct graphics output to PDF?
Next Topic: coyote graphics /iso command

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

Current Time: Wed Oct 08 13:28:24 PDT 2025

Total time taken to generate the page: 0.40463 seconds