Your command works just fine assuming the input is a Unix text file with tab-delimited fields, and that GNU paste
is used. On non-GNU systems, you would have to use
$ for i in {1..4}; do cut -f"$i" A.txt | paste -s - ; done
x row1 row2 row3 row4
column1 0 3 6 9
column2 1 4 7 10
column3 2 5 8 11
Notice the -
argument to paste
which tells it to read standard input.
You most definitely do not want to run this on 450k columns though as that would require reading the file 450000 times. You'd be better off using some other solution for that.
See, for example, "Transposing rows and columns".
If the above command is run on a DOS text file, it would produce the following output in the terminal:
x row1 row2 row3 row4
column1 0 3 6 9
column2 1 4 7 10
11
Redirecting the output to a new file and opening that file in the vim
editor would show
x row1 row2 row3 row4
column1 0 3 6 9
column2 1 4 7 10
column3^M 2^M 5^M 8^M 11^M
where each ^M
is a carriage return character (the extra character at the end of a DOS text line). These carriage returns makes the cursor move back to the beginning of the line which is why the only thing that is visible on the last line in the terminal is a tab and 11
(which overwrites the other columns).
Make sure that your input file is a Unix text file by running dos2unix A.txt
.