user3022917
user3022917

Reputation: 619

How to merge three text files into three columns on screen

How can I merge three text files into three columns on screen?

1   A   1
2   B   2
3   C   3
    D
    E

I tried...

paste file1.txt file2.txt file3.txt | column -s $'\t' -t

...but I always get

1   A   1
2   B   2
3   C   3
D
E

Thanks in advance for your help!

line 1-2 of file1.txt

USB Device Class ID:
CdRom&Ven_ZALMAN&Prod__Virtual_CD-Rom&Rev_

line 1-2 of file2.txt

USB Instance ID:
______XX00000001&1

line 1-2 of file3.txt

Last updated (Subkey):
2015-01-12 15:08:45 UTC+0000

Upvotes: 1

Views: 182

Answers (3)

lurker
lurker

Reputation: 58254

If you only have 3 files or a few to deal with you can do this:

$ paste foo[12].txt | expand -t 45 | paste - foo3.txt | expand -t 12
USB Device Class ID:                         USB Instance ID:           Last updated (Subkey):
CdRom&Ven_ZALMAN&Prod__Virtual_CD-Rom&Rev_   ______XX00000001&1         2015-01-12 15:08:45 UTC+0000
                                             ______XY0000000182
$

You need to choose the tab expansions 45 and 12 depending upon maximum line widths in foo1.txt and foo2.txt.

Upvotes: 0

auth private
auth private

Reputation: 1314

:|paste -d ' ' file1 - file2 - file3 | column -ts "| " combine many files as a table column -t and -s as a separator "| " .

the output will be like that

1    A    1
2    B    2
3    C    3
     D    
     E   

Upvotes: 0

karakfa
karakfa

Reputation: 67507

I don't know your input files, but paste works as intended.

$ paste <(seq 1 4) <(seq 10 17) <(seq 5 9)
1       10      5
2       11      6
3       12      7
4       13      8
        14      9
        15
        16
        17

Upvotes: 1

Related Questions