连接问题:抛出错误,连接额外的操作数

连接问题:抛出错误,连接额外的操作数

我想在已排序唯一数值的列上加入 3 个文件(尽管这些文件只有一列值),并以相同的前缀开头,例如“usi”。

现在,当我这样做的时候

join -j 1 ../Test_Data/usi* > ../Test_Data/join_output.txt

我发现以下错误:

join: extra operand `usi_rtree_lw_100000.txt'
Try `join --help' for more information.

有任何想法吗?

答案1

join仅接受 2 个文件加入。要操作 3 个文件,您必须使用 2 个join调用:

join -j 1 <(join -j 1 ../Test_Data/usi-1 ../Test_Data/usi-2) ../Test_Data/usi-3 > ../Test_Data/join_output.txt

上面的命令需要bash,因为使用进程替换。如果您使用其他 shell,请指定哪个 shell。

更新根据评论。
如果您只知道文件名模式而不知道确切的文件名,请让 shell 扩展该模式,捕获数组中的扩展列表,然后使用数组元素作为参数:

file=(../Test_Data/usi*)
join -j 1 <(join -j 1 "${file[0]}" "${file[1]}") "${file[2]}"

答案2

POSIX外壳变种工作的人的回答:

  1. printf '"%s" ' ../Test_Data/usi* | { read a b c ; join $a $b | join - $c ; }

  2. set -- ../Test_Data/usi* ; join "$1" "$2" | join - "$3"

相关内容