Unix连接两个以上的文件

Ste*_*ner 4 perl text join cut paste

我有三个文件,每个文件都有一个ID和一个值.

sdt5z@fir-s:~/test$ ls
a.txt  b.txt  c.txt
sdt5z@fir-s:~/test$ cat a.txt 
id1 1
id2 2
id3 3
sdt5z@fir-s:~/test$ cat b.txt 
id1 4
id2 5
id3 6
sdt5z@fir-s:~/test$ cat c.txt 
id1 7
id2 8
id3 9
Run Code Online (Sandbox Code Playgroud)

我想创建一个看起来像这样的文件......

id1 1 4 7
id2 2 5 8
id3 3 6 9
Run Code Online (Sandbox Code Playgroud)

...最好使用单个命令.

我知道连接和粘贴命令.粘贴将每次复制id列:

sdt5z@fir-s:~/test$ paste a.txt b.txt c.txt 
id1 1   id1 4   id1 7
id2 2   id2 5   id2 8
id3 3   id3 6   id3 9
Run Code Online (Sandbox Code Playgroud)

加入效果很好,但一次只有两个文件:

sdt5z@fir-s:~/test$ join a.txt b.txt 
id1 1 4
id2 2 5
id3 3 6
sdt5z@fir-s:~/test$ join a.txt b.txt c.txt 
join: extra operand `c.txt'
Try `join --help' for more information.
Run Code Online (Sandbox Code Playgroud)

我也知道粘贴可以使用" - "将STDIN作为参数之一.例如,我可以使用以下命令复制join命令:

sdt5z@fir-s:~/test$ cut -f2 b.txt | paste a.txt -
id1 1   4
id2 2   5
id3 3   6
Run Code Online (Sandbox Code Playgroud)

但我仍然不知道如何修改它以容纳三个文件.

因为我在perl脚本中执行此操作,所以我知道我可以执行类似将其置于foreach循环中的内容,例如join file1 file2> tmp1,join tmp1 file3> tmp2等等.但这会变得混乱,我想用一个班轮做这件事.

Ser*_*ner 12

join a.txt b.txt|join - c.txt

应该足够了