I have several folders, each containing a text file, which I would to transpose (convert lines to columns) in Bash. I have set this up with awk inside a for loop, however I have an issue with the last line, which is never transposed correctly.
This is my input.txt
ID1 11208 13391 16070 19383
ID2 6691 8489 8723 7493
ID3 5768 6004 7754 7614
This is my output.txt with the error.
ID1 ID2 ID3
11208 6691 5768
13391 8489 6004
16070 8723 7754
19383
7493
7614
This is what I want
ID1 ID2 ID3
11208 6691 5768
13391 8489 6004
16070 8723 7754
19383 7493 7614
My awk one liner is :
input.txt | awk '{for(i=1; i<=NF; i++) A[i]=A[i] (NR>1?OFS:x) $i} END{for(i=1; i<=NR; i++) print A[i]}' OFS="\t" > output.txt
Thank you all in advance for your time