The idea is to have both file1 and file2 in an order such that it is just a stepwise ladder walk. Our mythical ladder walker has one foot on ladder1 and one foot on ladder2 and if a foot moves, it moves upward.
This takes a long time:
A step-wise walker algorithm is a merge of 2 sorted files and is much faster because all that is needed is to decide who goes next, like 2 cars at a stop sign.foreach line in file1... { loop through lines in file2... { ...many comparisons... decide which one is next } }
foreach line in file1... { # insert file2 line(s) that should go before the # current line from file1 while {the current line in file2 is "next" in total order} { output that line from file2; move to next line in file2 } output the file1 line } output rest of file2 lines (if any)
In reply to Re^2: Merging larges files by columns
by Marshall
in thread Merging larges files by columns
by ScottJohn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |