linux中实现矩阵转置

1、测试数据

root@PC1:/home/test# ls
a.txt
root@PC1:/home/test# cat a.txt
i u k f
2 3 8 7
s j 9 4

 

2、利用for循环转置

root@PC1:/home/test# ls
a.txt
root@PC1:/home/test# cat a.txt
i u k f
2 3 8 7
s j 9 4
root@PC1:/home/test# for i in `seq $(head -n 1 a.txt | awk '{print NF}')`; do cut -d " " -f $i a.txt | paste -s -d " " >> b.txt; done
root@PC1:/home/test# ls
a.txt  b.txt
root@PC1:/home/test# cat b.txt
i 2 s
u 3 j
k 8 9
f 7 4

 

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本