LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

insert in text file

Solved!
Go to solution
Hello, 

I have an application that generates a measurement files (text) of several hundred Mo. 
How can I insert text in the file without having to read all the contents (I know the position where to insert a text in this file). 

Thank you in advance.

Matthias Baudot | Software Architect | Founder & Owner at STUDIO BODs | DQMH® Consortium Board Member & Trusted Advisor

STUDIO BODs     LabVIEW Champion     Certified Professional Instructor     DQMH Trusted Advisor     DQMH Consortium Board Member     GCentral Sponsor

 Check out my LabVIEW presentations and videos!

0 Kudos
Message 1 of 13
(6,084 Views)

How big is a "Mo"? 😮

 

A file is just one linear string of characters, so if you want to insert (moving everything above the insert point up) you need to read everything from the insert point, write your data at the insert point, and write the old data after it. (Would you need help with that?)

 

If you want to overwrite a certain section with new data, keeping the file size constant, things are a bit easier.

 

 

0 Kudos
Message 2 of 13
(6,069 Views)

Excuse me for this francisism. I meant Mb (Megabyte) and not Mo (which is Megaoctet in french).

 

Your definition of insert feat with what I want to do. So if I understand correctly, It's impossible to insert (and not overwrite) data in a file text without having to read the data located before and after my insert position ?

 

You see the problem that I have, in my case, it is not possible to have read 800MB of data to insert 15 characters of text. 

 

Other ideas, or it is really impossible ???

 

Thanks. 


Matthias Baudot | Software Architect | Founder & Owner at STUDIO BODs | DQMH® Consortium Board Member & Trusted Advisor

STUDIO BODs     LabVIEW Champion     Certified Professional Instructor     DQMH Trusted Advisor     DQMH Consortium Board Member     GCentral Sponsor

 Check out my LabVIEW presentations and videos!

0 Kudos
Message 3 of 13
(6,057 Views)

Hi studiobods,

 

Altenbach was not implying that it was impossible to do, but that you will need to read the entire file in order to manipulate it..  Or at least read the section before the insertion, insert the text, then read and insert the rest.  All possible..

 

En francais maintenant.

 

C'est possible d'accomplir ce que tu decris.  Cependant, il va falloir faire la lecture du fichier en entier, afin de le manipuler (ajouter le text).  Sinon, il serait possible de (1) faire la lecture du fichier jusqu'au point ou tu desires ajouter le text, (2) ajouter le texte, et (3) lire le reste du fichier et l'incorporer avec (1 & 2).

 

R

0 Kudos
Message 4 of 13
(6,053 Views)

This means that I have to read my 800MB of data that I want absolutely not. 
It therefore seems impossible to do what I want.

 

Thank you for your help anyway


Matthias Baudot | Software Architect | Founder & Owner at STUDIO BODs | DQMH® Consortium Board Member & Trusted Advisor

STUDIO BODs     LabVIEW Champion     Certified Professional Instructor     DQMH Trusted Advisor     DQMH Consortium Board Member     GCentral Sponsor

 Check out my LabVIEW presentations and videos!

0 Kudos
Message 5 of 13
(6,050 Views)

studiobods wrote:

So if I understand correctly, It's impossible to insert (and not overwrite) data in a file text without having to read the data located before and after my insert position ?


No, you did not understand correctly.

 

IF you know the offset of the insert position, you don't need to read anything before it. All that will stay in place. So the complexity of the operation depends on your parameters. If you have a 800MB file and need to insert at position 799, all you need is read the last 1MB, go back to offset, write the new data, and rewrite the 1MB you read earlier. If you need to insert near the beginning, the operation involves more data, of course.

 

Storing the data in a single 800MB file is not a good idea. Maybe you can split it into multiple files for better handling.

 

Hundreds of MB in a text file is typically too much anyway. Maybe using binary files would make things simpler. What kind of data is it?

 

 

Message 6 of 13
(6,033 Views)

 

Do you know where the insertion point is within the file?

 

or better yet...

 

How do you determine where you need to insert the text (the location within the file)?  Can you describe that?

 

R

0 Kudos
Message 7 of 13
(6,013 Views)
Solution
Accepted by topic author mbaudot

I use the text file for storing measurements. Here is an example of my measurement files, but imagine that there is several thousands lines of measures below.

I need to insert text at the second line, after "Liste de lecture :", but I don't really know in advance the lenght of the string I have to insert.

Presently, I assume that the text I have to insert do not exceed 1000 characters. So when I initialise my file, I write 1000 space characters after "Liste de lecture :". Then when I have to insert my text, I overwrite this spaces with the correct data.

It works very well.

If someone have a better idea...

 

Thanks 


Matthias Baudot | Software Architect | Founder & Owner at STUDIO BODs | DQMH® Consortium Board Member & Trusted Advisor

STUDIO BODs     LabVIEW Champion     Certified Professional Instructor     DQMH Trusted Advisor     DQMH Consortium Board Member     GCentral Sponsor

 Check out my LabVIEW presentations and videos!

Message 8 of 13
(5,989 Views)
Is there a specific reason why you need to insert as opposed to simply append to the file (which is a lot easier)?
0 Kudos
Message 9 of 13
(5,984 Views)

Yes, I have the data that I want to insert only after all the measures are written in the file. I don't know the number of lines of measures anyway, and I have to know exactely at which line is located the text I have inserted for post-processing on this file.

Moreover, for better readability of the file, I want this data (written after "Liste de lecture :") appears at the top of the file. It's like a parameter that describe the conditions of the measures... 


Matthias Baudot | Software Architect | Founder & Owner at STUDIO BODs | DQMH® Consortium Board Member & Trusted Advisor

STUDIO BODs     LabVIEW Champion     Certified Professional Instructor     DQMH Trusted Advisor     DQMH Consortium Board Member     GCentral Sponsor

 Check out my LabVIEW presentations and videos!

0 Kudos
Message 10 of 13
(5,982 Views)