Message Boards Message Boards

0
|
9881 Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Merging Large Text Files Without Reading Entire File

Posted 10 years ago
POSTED BY: Bob Stephens
9 Replies
Posted 10 years ago
POSTED BY: Bob Stephens
Posted 10 years ago

Yes, here is another solution I came up with - last question, what is the best way to export this result to a file if we read everything in at once?

enter image description here

POSTED BY: Bob Stephens
Posted 10 years ago

Looks like the issue is that each row is currently a string and so the Join function is not getting the number of expected elements

POSTED BY: Bob Stephens

A direct (but not very elegant) way could be:

ClearAll["Global`*"]
SetDirectory[NotebookDirectory[]];
input1 = Import["first.txt", "Data"];
input2 = Import["second.txt", "Data"];
result = Join[input1, input2, 2];
Export["result.txt", 
  StringReplace[
   ToString[result], {"}, {" -> "\n", ", " -> "\t", "{{" -> "", 
    "}}" -> ""}]];

But I have to confess that this is not solving your primary question: This way the entire input files have to be red in first.

Henrik

POSTED BY: Henrik Schachner
Posted 10 years ago

Adding sample files to discussion.

Attachments:
POSTED BY: Bob Stephens
Posted 10 years ago
POSTED BY: Bob Stephens
POSTED BY: Henrik Schachner

Try with:

Join[list1, list2, 2]

Cheers Henrik

POSTED BY: Henrik Schachner
Posted 10 years ago

Sorry, text formatting (ironically) in the web app does not clearly illustrate the problem. See image below

thanks

enter image description here

POSTED BY: Bob Stephens
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract