. f_askfname.sh
. f_askstring.sh
ask_filename "Target File( Blank is Cancel. ): " 1
if [ $? -ne 0 ]; then
echo "*** Canceled."
return 1
fi
FILE1=${_STR}
echo "Target File is \"${FILE1}\""
ask_string "Save File [${FILE1}.rotate]; " 1
if [ $? -ne 0 ]; then
FILE2="${FILE1}.rotate"
else
FILE2=${_STR}
fi
echo "Save File is \"${FILE2}\""
awk -F'\t' 'BIGIN{maxi=0;}
{i=NF;y[NR]=$0;if(i>maxi){maxi=i;}}\
END{\
for(j=1;j<=maxi;j++){\
for(i=1;i<=NR;i++){\
k=split(y[i],s);if(j in s){printf("%s%s",s[j],FS);;delete s[j];}}
printf("%s",RS);}\
}' ${FILE1} > ${FILE2}
echo "*** Successful."
unset FILE1 FILE2 _STR
$ cat 1.txt
1 g
2 f
3 e
4 d
5 c
6 b
7 a
$ ./rotate.sh
Target File( Blank is Cancel. ): 1.txt
Target File is "1.txt"
Save File [1.txt.rotate];
Save File is "1.txt.rotate"
*** Successful.
$ cat 1.txt.rotate
1 g 2 f 3 e 4 d 5 c 6 b 7 a