views:

150

answers:

1

I have large data files of values on a 2D grid. They are organized such that subsequent rows of data in the grid are subsequent lines in the file. Each column is separated by a tab character. Essentially, this is a CSV file, but with tabs instead of columns.

I need the transpose the data (first row becomes first column) and output it to another file. What's the best way to do this? Any language is okay (I prefer to use Perl or C/C++). Currently, I have Perl script just read in the entire file into memory, but I have files which are simply gigantic.

+1  A: 

The simplest way would be to make multiple passes through your input, extracting a subset of columns on each pass. The number of columns would be determined by how much memory you wanted to use and how many rows are in the input file.

For example:

On pass 1 you read the entire input file and process only the first, say, 10 columns. If the input had 1 million rows, the output would be a file with 1 million columns and 10 rows. On the next pass you would read the input again, and process columns 11 thru 20, appending the results to the original output file. And so on....

Jim Garrison