LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read text file and get value of each row

Solved!
Go to solution

Hello ,
I need to read a .txt file (log.txt) and extract the data from each line and put it in a csv file. The parser file output example.csv is what I want to have.
I succeeded in reading the file, but how do I extract the data from each line?
How do I do this?
Thanks in advance

0 Kudos
Message 1 of 15
(1,948 Views)

Hi Ngouda,

 

Here is a simple example that retrieves some data from your log file using the JSONtext package and outputs it to a CSV file:

 

raphschru_0-1700233608977.png

 

You may have to adjust the JSON paths, post-process elements to reformat them at your need, adjust the output file delimiter, file names, etc...

 

Regards,

Raphaël.

Message 2 of 15
(1,928 Views)

We are missing subVIs. Is the included CSV file exactly what you want as desired output for the given input file? Looks like "semicolon delimited", not "comma delimited" as csv typically would indicate. Do you really need all these blank fields?

 

Your code contains completely silly Rube Goldberg constructs such as the following:

 

altenbach_0-1700235083339.png

 

 

(If you are autoindexing, you don't need to get the size and wire to N! Building an array with one element, then getting that element is a NOOP.!)

 

0 Kudos
Message 3 of 15
(1,913 Views)

@altenbach wrote:

 

altenbach_0-1700235083339.png

 

 

(If you are autoindexing, you don't need to get the size and wire to N! Building an array with one element, then getting that element is a NOOP.!)

 


May be kind of "orphan" refactoring, because probably some iterations ago here was completely other code, which was removed. I don't belive that it was created "from the scratch" in such form. Sometimes I have "similar" funny artefacts in my old code, even after 20+ years experience. Just round refactoring, that all.

Message 4 of 15
(1,838 Views)

@Andrey_Dmitriev wrote:

@altenbach wrote:

 

altenbach_0-1700235083339.png

 

 

(If you are autoindexing, you don't need to get the size and wire to N! Building an array with one element, then getting that element is a NOOP.!)

 


May be kind of "orphan" refactoring, because probably some iterations ago here was completely other code, which was removed. I don't belive that it was created "from the scratch" in such form. Sometimes I have "similar" funny artefacts in my old code, even after 20+ years experience. Just round refactoring, that all.


From what I saw in the original code, this was an artifact of just trying anything trying to get something to work instead of actually figuring out what each item does to construct the solution.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 15
(1,817 Views)

@crossrulz wrote:
From what I saw in the original code, this was an artifact of just trying anything trying to get something to work instead of actually figuring out what each item does to construct the solution.

Yes, following the adage that even a blind chicken finds a grain of corn once in a while, we can just randomly throw more and more code at it and as long as there are no broken wires there is a finite chance that it will run and do "something". Wash. Rinse. Repeat.

 

Same applies for the file reading (it is not clear on which planet "open or create" would make sense to read an existing file. 😄 fortunately, the file dialog is configured to pick an existing file, so this is moot.)

:

 

altenbach_0-1700321982708.png

(... and no, I would not do it this way either... )

0 Kudos
Message 6 of 15
(1,806 Views)

Hi @raphschru, hi @all
thank you for your answers.
When I posted my first question I had a lot of things to do I didn't have time, I modified an old vi hence some duplicates that some people have noticed.
I thought about my problem and I noticed that my log.txt file had this structure (see Archetecture_of_file_log.txt).
So I thought of making a cluster).
My last, probably simple question is:
How do I save Array data in the output.csv file?
Thanks in advance

0 Kudos
Message 7 of 15
(1,752 Views)

Hi @Andrey_Dmitriev,
It was exactly that !

0 Kudos
Message 8 of 15
(1,749 Views)

Sorry, I don't have your toolkit. Can you run your VI until the "Array" indicator contains data, then select that indicator and "exit...make selected value default). Not copy it to a new VI and attach that here.

 

I doubt that the current example output is really what you want (here's how a small part looks in notepad++):

 

altenbach_0-1700497799464.png

 

0 Kudos
Message 9 of 15
(1,713 Views)

Here's code that would blindly graph all data as %d, then just write it as 1D array using a linefeed as delimiter.

 

You need to figure out how the date/time is encoded in some of these integers and translate it onto a proper time format (not shown), (Yes, there are more efficient ways, but start with that).

 

altenbach_0-1700504100282.png

 

 

0 Kudos
Message 10 of 15
(1,707 Views)