linux 中实现将 不连续的一列数字间隔补充为0或者指定任意字符
001、
[root@pc1 test2]# ls index.txt [root@pc1 test2]# cat index.txt ## 测试的一列数字 2 3 4 8 9 11 [root@pc1 test2]# awk '{if(NR == 1) {a = $0 - 0 - 1; for (i = 1; i <= a; i++) {print "0"};print $0; tmp = $0} else if ($0 - tmp != 1){a = $0 - tmp - 1; for (i = 1; i <= a; i++) {print "0"}; print $0; tmp = $0 } else {print $0; tmp = $0}}' index.txt 0 ## 将非连续的数字间隔全部补充为0 2 3 4 0 0 0 8 9 0 11

。

浙公网安备 33010602011771号