Combine text from two files, output to another

前端 未结 2 1113
太阳男子
太阳男子 2021-01-25 00:25

i\'m having a bit of a problem and i\'ve been searching allll day. this is my first Unix class don\'t be to harsh.

so this may sound fairly simple, but i can\'t get it

2条回答
  •  [愿得一人]
    2021-01-25 01:17

    In this case join command will also work,

    join -1 1 -2 1 <(sort file1) <(sort file2)
    

    Description

    -1 -> file1
    1  -> first field of file1 (common field)
    -2 -> file2
    1 -> first field of file2 (common field)
    
    
    **cat file1**
    
    David 734.838.9801
    Roberto 313.123.4567
    Sally 248.344.5576
    Mary 313.449.1390
    Ted 248.496.2207
    Alice 616.556.4458
    Frank 634.296.1259
    
    **cat file2**
    
    Roberto Tuesday 2
    Sally Monday 8
    Ted Sunday 16
    Alice Wednesday 23
    David Thursday 10
    Mary Saturday 14
    Frank Friday 15
    

    output

    Alice 616.556.4458 Wednesday 23
    David 734.838.9801 Thursday 10
    Frank 634.296.1259 Friday 15
    Mary 313.449.1390 Saturday 14
    Roberto 313.123.4567 Tuesday 2
    Sally 248.344.5576 Monday 8
    Ted 248.496.2207 Sunday 16
    

提交回复
热议问题