linux中实现将宽列数据按照指定列堆叠输出

发布时间 2023-09-26 00:15:19作者: 小鲨鱼2018

 

001、

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt
001 002 003 004 005 006 007 008 009 010
011 012 013 014 015 016 017 018 019 020
021 022 023 024 025 026 027 028 029 030
031 032 033 034 035 036 037 038 039 040
041 042 043 044 045 046 047 048 049 050
[root@pc1 test01]# for i in $(seq 1 2 $(head -n 1 a.txt | awk '{print NF}')); do let j=$i+1; cut -d " " -f $i-$j a.txt >> result.txt; done
[root@pc1 test01]# ls
a.txt  result.txt
[root@pc1 test01]# cat result.txt
001 002
011 012
021 022
031 032
041 042
003 004
013 014
023 024
033 034
043 044
005 006
015 016
025 026
035 036
045 046
007 008
017 018
027 028
037 038
047 048
009 010
019 020
029 030
039 040
049 050