unix - unix 中两个文件的左外连接

标签 unix join

我需要在两个字段上加入两个文件。但是,即使连接失败,我也应该检索文件 1 中的所有值,就像左外连接一样。

文件 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
使用的选项:

电话 : 分隔符。
: 决定必须打印未配对行的文件编号。
join -t '|' file1 file2 -a2会做 右外连接 .

sample 运行

   [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 - unix 中两个文件的左外连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13382566/

相关文章:

linux - 如何在 Linux 中启动 Apache 服务器

unix - 从 Bash 脚本在线程中运行 UNIX 命令

mysql - SQL JOIN 表和 GROUP BY 以获得正确的行

javascript - 使用 for 循环在一个字符串中插入多个字符串

mysql - 不确定这个右外连接的结果是什么

linux - 为什么我不能将 Unix Nohup 与 Bash For 循环一起使用?

maven - 在不同目录下执行命令

regex - 在 `find` 中工作的正则表达式

mysql - 在 MySQL 中组合多个 SELECT 和 CREATE 查询

php - SQL join into join 创建好数组