col-row.sh
#!/bin/bash
filename=$1
#m=`wc -l filename | cut -f 1 -d ' '`
#echo $m
n=`head -1 $filename | wc -w`
for i in `seq $n`
# get contents of a col and print as a row
do
echo `awk '{print $'$i'}' ORS="\t" $filename`
done
代码运行(速度较慢)
sh col-row.sh input.txt > output.txt
col-row2.sh
#!/bin/bash
awk '{for(i=1;i<=NF;i++)a[NR,i]=$i}END{for(j=1;j<=NF;j++)for(k=1;k<=NR;k++)printf k==NR?a[k,j] RS:a[k,j] FS}' input.txt > output.txt
代码运行(速度较快)
sh col-row2.sh
网友评论