ID と値を持つ 3 つのファイルがあります。
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
このようなファイルを作成したいのですが...
id1 1 4 7
id2 2 5 8
id3 3 6 9
...できれば単一のコマンドを使用します。
結合コマンドと貼り付けコマンドを認識しています。貼り付けは毎回 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
結合はうまく機能しますが、一度に 2 つのファイルのみです。
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.
また、「-」を使用することで、paste が STDIN を引数の 1 つとして使用できることも認識しています。たとえば、次を使用して join コマンドを複製できます。
sdt5z@fir-s:~/test$ cut -f2 b.txt | paste a.txt -
id1 1 4
id2 2 5
id3 3 6
しかし、これを 3 つのファイルに対応するように変更する方法がまだわかりません。
私はこれを perl スクリプト内で行っているので、これを foreach ループ内に入れるようなことができることを知っています。たとえば、join file1 file2 > tmp1、join tmp1 file3 > tmp2 などです。ワンライナーでこれを行うには。