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

 

posted @ 2022-03-23 08:45  小鲨鱼2018  阅读(546)  评论(0编辑  收藏  举报