Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Please edit your question and explain how the files should be joined. I think you want to use the first and second fields as the key to join on, but it isn't very clear. Commented Oct 29, 2021 at 17:14
  • Thanks, I've edited the question. But yes, you're completely right, the first and second fields would be the key. Commented Oct 29, 2021 at 17:17
  • Please explain in words the entire process. Why are there 0s being added? how do we know how many to add? Since you tell us that your script doesn't do what you need, we can't use the script to figure out your requirements, so you need to explain them. Note that you are using I in some places but i in others. That is likely the main issue. Commented Oct 29, 2021 at 17:26
  • I've added more explanation to this question. Basically, zeroes are meant to fill missing values (e.g. file2.txt doesn't have a row with 20 102 in the first two fields, so in the result file row with those fields will look like 20 102 5 6 7 8 0 0 0 0). So, we will always add 4 zeroes, it's just a matter of whether it will be fields [3-6] or [7-10] that are filled with them. I've edited upper characters, I guess they popped up while copy-pasting, no such things in the code itself. Commented Oct 29, 2021 at 17:51
  • 1
    Regarding Considering that I will use very large files for merging, is it reasonable to use arrays memory-wise? - what do you mean by "very large" - 1000 lines, 1 million lines, 1MB, 1GB, 100GB, or something else? Are your files always sorted on the first 2 fields as in your example or not? Do you care about the output order and, if so, what should that be - input order or numerical ascending or something else? Please edit your question to provide all answers. Commented Oct 29, 2021 at 19:14