I have several file named BC**-tmp1.tsv
that are the first iteration of a blast output and other file named BC**-tmp2.tsv
that are the second iteration.
Example of file BC02-tmp1.tsv
(separator : \t
) :
BC02 Aaa 2712 94 0 99.073 2053209 CP023507.1 1597 A
BC02 Bbb 2712 94 0 99.073 2053209 CP023507.1 1597 B
BC02 Ccc 2712 94 0 99.073 2053209 CP023507.1 1597 C
BC02 Ddd 2712 94 0 99.073 2053209 CP023507.1 1597 D
Example of file BC02-tmp2.tsv
(separator : \t
) :
BC02 Eee 2712 94 0 99.073 2053209 CP023507.1 1597 E
BC02 Fff 2712 94 0 99.073 2053209 CP023507.1 1597 F
BC02 Ggg 2712 94 0 99.073 2053209 CP023507.1 1597 G
BC02 Hhh 2712 94 0 99.073 2053209 CP023507.1 1597 H
My goal is to concatenate all those file by pair (iteration 1 + iteration 2) in a specific way.
Example of result with the example BC02
in the final file:
BC02 Aaa 2712 94 0 99.073 2053209 CP023507.1 1597 A B C BC02 Eee 2712 94 0 99.073 2053209 CP023507.1 1597 E F G
So to be more precise I want to print (on the same line) the first line of the BC**-tmp1.tsv
file, then the last column of the second line, then the last column of the third line, then the first line of the BC**-tmp2.tsv
file, then the last column of the second line, then the last column of the third line. And that for each pair of Barcodes.
Note: the second iteration file is not always present.
So far I managed to gather the associated files in a shell for
loop, but I don't know how to do the rest:
touch template.tsv
for bla in *-tmp1.tsv; do
r="$(basename -s "-tmp1.tsv" $bla)"
awk 'FNR==1' $bla >> template.tsv
awk 'FNR==1' $r-tmp2.tsv >> template.tsv;
done
Do you know how to do that ?
EDIT simpler input/output:
Input:
$ head BC02-tmp*.tsv
==> BC02-tmp1.tsv <==
a b B
a c C
a d D
a e E
==> BC02-tmp2.tsv <==
a w W
a x X
a y Y
a z Z
Output:
a b B C D a w W X Y
print $0, tmp[1] " " tmp[2]
.