用 | 连接,对三个文件进行排序

问题描述 投票:0回答:1

我试图理解 CLI 的“加入”,结果是这样的:

文件1:

1901,Jean Henri Dunant,M
1901,Frederic Passy,M
1902,Elie Ducommun,M
1905,Baroness Bertha Sophie Felicita Von Suttner,F
1910,Permanent International Peace Bureau,

文件2:

Jean Henri Dunant,Switzerland 
Frederic Passy,France 
Elie Ducommun,Switzerland 
Baroness Bertha Sophie Felicita Von Suttner

文件3:

Belgium,Brussels
France,Paris
Italy,Rome
Switzerland

我已经尝试过了

join -t, -1 2 -o 1.2 2.2 nobel_laureates.txt nobel_nationalities.txt | sort -k2 -t, | join -t, -e "<<NULL>>" -1 2 -o 1.1 2.2 - capitals.txt

并且得到了

usage: join [-a fileno | -v fileno ] [-e string] [-1 field] [-2 field]
            [-o list] [-t char] file1 file2
usage: join [-a fileno | -v fileno ] [-e string] [-1 field] [-2 field]
            [-o list] [-t char] file1 file2

有什么问题吗?

bash join pipe zsh
1个回答
0
投票

摘自

join
POSIX 规范

-o 列表

构造输出行以包含list中指定的字段,其中每个元素应具有以下两种形式之一:

  1. file_number.field,其中 file_number 是文件编号,field 是十进制整数字段编号
  2. 0(零),代表连接字段

list的元素应为

<comma>
分隔或
<blank>
分隔
,如XBD 12.2实用语法指南的指南8中所指定。应为所有选定的输出行写入由list指定的字段。由list选择的未出现在输入中的字段应被视为空输出字段。 (请参阅 -e 选项。)仅应写入特别要求的字段。 应用程序应确保list是单个命令行参数

正如你可以在我在上一段中强调的文字中看到的,

join -o 1.2 2.2
应该写成
join -o 1.2,2.2
join -o '1.2 2.2'

© www.soinside.com 2019 - 2024. All rights reserved.