LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read data from multiple files and append in columns in one file

Solved!
Go to solution

Hi Guys,

I have a problem in appending data from files in different columns. I have attachement has file A and B which I am reading and not able to get data as in file Result.txt. Please comment on how can I do this

 

 

Download All
0 Kudos
Message 1 of 6
(3,280 Views)

Here is the Result.txt file.

0 Kudos
Message 2 of 6
(3,279 Views)
Solution
Accepted by topic author jason33

You have to append the data from all files before doing a single write.

Message 3 of 6
(3,262 Views)

You cannot append columns to an existing file. Since the data is arrange line-by-line as one long linear string in the file, you can only append rows. A new row needs to be interlaced into the original file, shifting everything else. If you want to append rows, you need to build the entire output structure in memory and then write all at once.

 

(I also don't think you need to set the file positions, it will be remembered from the last write operation.)

 

Unless the files are gigantic, here's what I would do:

 

(Also note that some of your rows have an extra tab at the end. If this is normal, you need a little bit more code to strop out empty columns. I include cleaned up files in the attachment. I also would not call them A.txt.txt etc. A plain A.txt is probably sufficient.)

 

EDIT: It seems Dennis's solution is similar ;))

Download All
Message 4 of 6
(3,234 Views)

The file would be gigantic. Wount this VI work for n number of files with a couple of hundred MB each.

0 Kudos
Message 5 of 6
(3,226 Views)

You'll probably run out of memory trying to do all in one swoop.

 

I assume that all files have the same size, so just read a good chunk (= same number of lines) of each file, merge, write, read the next chunks, append, etc. For this you might want to go back to low level file IO.

 

See how far you get. 🙂

0 Kudos
Message 6 of 6
(3,213 Views)