我有三个文件,每个文件都有一个ID和一个值。Unix加入两个以上的文件
[email protected]:~/test$ ls
a.txt b.txt c.txt
[email protected]:~/test$ cat a.txt
id1 1
id2 2
id3 3
[email protected]:~/test$ cat b.txt
id1 4
id2 5
id3 6
[email protected]:~/test$ cat c.txt
id1 7
id2 8
id3 9
我想创建一个类似如下的文件...
id1 1 4 7
id2 2 5 8
id3 3 6 9
...最好使用一个命令。
我知道加入和粘贴命令。粘贴每次都会重复的ID列:
[email protected]:~/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
加入效果很好,但在同一时间只有两个文件:
[email protected]:~/test$ join a.txt b.txt
id1 1 4
id2 2 5
id3 3 6
[email protected]:~/test$ join a.txt b.txt c.txt
join: extra operand `c.txt'
Try `join --help' for more information.
我也知道这种糊可以采取STDIN为一体通过使用“ - ”参数。例如,我可以使用以下命令来复制连接命令:
[email protected]:~/test$ cut -f2 b.txt | paste a.txt -
id1 1 4
id2 2 5
id3 3 6
但我仍然不确定如何修改此以容纳三个文件。
因为我在perl脚本中这样做,我知道我可以做一些事情,比如把它放在一个foreach循环中,就像加入file1 file2> tmp1,加入tmp1 file3> tmp2等。但是这会变得凌乱,我想用一行代码来做到这一点。
我也知道这是一个SQL内部连接的小菜一碟,但我不想先将所有这些加载到数据库中。 – 2012-02-09 14:46:43