- 论坛徽章:
- 6
|
本帖最后由 1cpuer 于 2018-11-20 15:14 编辑
Here is an example that treats its input as a two-dimensional array of fields; it rotates this array 90 degrees clockwise and prints the result. It assumes that all lines have the same number of elements:
{ if (max_nf < NF) max_nf = NF max_nr = NR for (x = 1; x <= NF; x++) vector[x, NR] = $x}END { for (x = 1; x <= max_nf; x++) { for (y = max_nr; y >= 1; --y) printf("%s ", vector[x, y]) printf("\n") }}
When given the input:
1 2 3 4 5 6
2 3 4 5 6 1
3 4 5 6 1 2
4 5 6 1 2 3
the program produces the following output:
4 3 2 1
5 4 3 2
6 5 4 3
1 6 5 4
2 1 6 5
3 2 1 6
https://www.gnu.org/software/gawk/manual/gawk.html#Arrays
文件:
123456
abcd
2345678
空格需求兼容 ?
|
|