Use awk for row and column conversions
Suppose you have a file test that contains data that follows the following format:
Same row of data, 1 spaces between words ""
Each row has the same amount of data, the same number
Processing commands:
awk ' {for (i=1;i<=nf;i=i+1) {a[nr,i]= $i}}end{for (j=1;j<=nf;j++) {str=a[1,j];for (i=2;i<=nr;i++) {STR=STR "" a [I,j]} Print str} ' test
Brief description:
Nr-number of Record-the line that is currently being processed is the number of rows (because awk is a stream processing tool, one row at a line, so NR is constantly increasing by 1); the Nr referenced in the end is the Nr after the text is processed
Fnr-file number of Record-the line currently being processed is the first line of the currently processed file
Nf-number of Fileds-How many column data the current row has (this is recalculated in each row according to the set delimiter, and the default delimiter is any contiguous number of whitespace characters)
Brief analysis of processing process:
The first step is to put the data in the text into a 2-dimensional array, stored in a manner identical to the text;
The column data is obtained when awk processes the text, and the Nr indicates that a few lines of text are processed and the output has a NR column; NF indicates the number of columns in the text and the output is NF.
Processing 2-dimensional arrays in the end module, converting rows of arrays into columns and depositing into another 2-D array str
Finally print out this array str
Linux text row and column conversions