linux 中实现数据按照行进行展开

 

001、

[root@PC1 test]# ls
coordinate.txt 
[root@PC1 test]# cat coordinate.txt                                      ## 测试数据
3 MMM
5 GGG
8 QQQ
[root@PC1 test]# awk '{if(NR == 1) {print $1 -1, $0; a=$1} else {print $1 - a - 1, $0; a=$1}}' coordinate.txt      ## 生成打印空行的序列
2 3 MMM
1 5 GGG
2 8 QQQ
[root@PC1 test]# awk '{if(NR == 1) {print $1 -1, $0; a=$1} else {print $1 - a - 1, $0; a=$1}}' coordinate.txt > coordinate2.txt     ## 将需要打印的数据保存为文件
[root@PC1 test]# cat coordinate2.txt
2 3 MMM
1 5 GGG
2 8 QQQ
[root@PC1 test]# cat coordinate2.txt | while read {i,j}; do seq $i | while read k; do echo "" >> result; done; echo $j >> result; done
[root@PC1 test]# ls
coordinate2.txt  coordinate.txt  result
[root@PC1 test]# cat result        ## 结果文件


3 MMM

5 GGG


8 QQQ
[root@PC1 test]# cat -n result      ## 结果文件
     1
     2
     3  3 MMM
     4
     5  5 GGG
     6
     7
     8  8 QQQ

 

posted @ 2022-12-25 13:20  小鲨鱼2018  阅读(34)  评论(0编辑  收藏  举报