I am using paste to merge three text files (which do not require sorting) into a single document with three columns.
paste a.txt b.txt c.txt
I'd like elements that the columns have in common to occupy the same row without sharing it with non-matching elements (which they currently do). By the same token, unique elements should have their own rows. The elements in each column should preserve their original order.
Here's a simple example.
Input
1 1 1
2 2 2
3 4 4
5 5 5
1 1 2
3 3 3
Desired Output
1 1 1
2 2 2
3
4 4
5 5 5
1 1
2
3 3 3
Here's a more complicated example.
Input
000 000 000
002 002 001
006 006 006
008 008 007
009 009 009
011 012 010
013 013 013
015 015 014
016 016 016
018 019 017
020 020 020
021 021 022
024 024 024
026 025 025
028 026 026
118 028 027
119 118 118
032 119 117
036 032 032
037 033 033
039 034 034
040 037 037
042 039 038
043 040 040
045 042 041
046 043 043
048 045 044
046 046
049 047
Desired Output
000 000 000
001
002 002
006 006 006
007
008 008
009 009 009
010
011
012
013 013 013
014
015 015
016 016 016
017
018
019
020 020 020
021 021
022
024 024 024
025 025
026 026 026
027
028 028
118 118 118
117
119 119
032 032 032
033 033
034 034
036
037 037 037
038
039 039
040 040 040
041
042 042
043 043 043
044
045 045
046 046 046
047
048
049
Ideally, I'd like to use tools that are built in to Linux/Unix. I'd also like the output to remain a single document with three columns, e.g., > whatever.csv.
The closest I've been able to get is to run sdiff on the original text files, but although that correctly aligns elements that the files share in common, it does not handle the differences as I would like.