Unix上两个文件的左外部联接 [英] Left outer join on two files in unix

查看:121
本文介绍了Unix上两个文件的左外部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在两个字段上加入两个文件.但是,即使联接失败(如左外部联接),我也应该检索文件1中的所有值.

I need to join two files on two fields. However i should retrieve all the values in file 1 even if the join fails its like a left outer join.

文件1:

01|a|jack|d
02|b|ron|c
03|d|tom|e

文件2:

01|a|nemesis|f
02|b|brave|d
04|d|gorr|h

输出:

01|a|jack|d|nemesis|f
02|b|ron|c|brave|d
03|d|tom|e||

推荐答案

它是join -t '|' file1 file2 -a1

使用的选项:

t :定界符.
a :确定必须从中打印未配对行的文件号.

t: Delimiter.
a: Decides the file number from which the unpaired lines have to be printed.

join -t '|' file1 file2 -a2将执行右外部连接.

样品运行

   [aman@aman test]$ cat f1  
    01|a|jack|d

    02|b|ron|c

    03|d|tom|e
    [aman@aman test]$ cat f2
    01|a|nemesis|f

    02|b|brave|d

    04|d|gorr|h
    [aman@aman test]$ join -t '|'  f1 f2 -a1
    01|a|jack|d|a|nemesis|f

    02|b|ron|c|b|brave|d

    03|d|tom|e

这篇关于Unix上两个文件的左外部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆