同じタブ区切りの列構造を持つ 10 個のファイルがあります。各ファイルの列 8 と 9 をマージする必要があります。次の AWK コードを思いつきましたが、一度に 2 つのファイルしかマージできません。10 個のファイルすべてを同時にマージする方法を探していますが、これが実現可能かどうかわかりません。
すべてのファイル名が同じパターン (s1s2.txt、s3s4.txt、s5s6.txt、.... s19s20.txt) に従う
#!/bin/bash
awk '
BEGIN {
#load array with contents of the first file
while ( getline < "s1s2.txt" > 0)
{
s1s2_counter++
f1_8[s1s2_counter] = $8
f1_9[s1s2_counter] = $9
}
}
{OFS="\t"}
{ #output the columns 8 and 9 from the first file before the second file
print f1_8[NR],f1_9[NR], $8, $9
} ' s3s4.txt