Transpose
From BITS wiki
Invert rows and columns
suggests : column
[ Main_Page ]
transpose (=exchange) lines and columns from a separated text file ([1]). Both separator and line feed can be changed to match your data (see below). Can be piped to column to obtain a nicely padded table.
# the download is a source text that needs be compiled before you ca run it # you can 'build' such code by using the compiler gcc that may need to be installed first # compiling transpose is done as follows: gcc src/transpose.c -o transpose
The transpose command has a built-in help that can be called with '-h'
transpose -h Description: This software is released under the GPL license Reshapes delimited text data - amongst other things, it can transpose a matrix of plain text data. The input file (optional, otherwise stdin is used) should be the last argument provided Options: -v or --version displays version information -h or --help displays this helpful information -b or --block <integer> specify the blocksize (in bytes) for reading the input (default is 10kb) --fsep <character> sets field separator to specified character. Defaults is \t --lsep <character> sets line separator to specified character. Default is \n --fieldmax or -f <integer>ine separator sets the number of characters to allow for in each field (default is 64) --input or -i <integer>x<integer>[+<integer>+<integer>] specificies size and cropping of the input. Dimension order is rows, columns --output or -o <integer>x<integer> specificies dimensions for the output. Default is determined from the input dimensions and whether we are transposing. --limit or -l <integer>x<integer> when not input dimensions, allow for this size (rowsxcolumns) matrix. Default is 1000x1000 --transpose or -t indicates that the output matrix is to be filled in columnwise. When output dimensions are not specified (or equal the transpose of the input dimensions) the output is an exact transpose of the input.
# create example data with one missing value echo 'X column1 column2 column3 row1 0 1 2 row2 3 4 5 row3 6 7 8 row4 9 11' > ex.txt # !!! the delimiter in this file is 'space' and not tab # now replace spaces by tabs and transpose lines and columns (pivot | rotate) tr "\ " "\t" < ex.txt | transpose -t X row1 row2 row3 row4 column1 0 3 6 9 column2 1 4 7 column3 2 5 8 11 # try 'transpose --help'
References:
[ Main_Page ]