linux 中判断一组数据是否是等量递增

 

001、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt       ## 测试数据
1
2
3
4
5
6
7
8
9
10
[root@PC1 test]# awk '{if(NR == 1) {a = $0}; if(NR > 1 && $0 - a != 1) {print NR, "error"}; a = $0}' a.txt     ## 判断程序,判断是否每次递增1

 

 

002、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt           ## 测试数据
1
2
3
4000
5
6
777
877
9
10000
[root@PC1 test]# awk '{if(NR == 1) {a = $0}; if(NR > 1 && $0 - a != 1) {print NR, "error"}; a = $0}' a.txt       ## 判断程序
4 error
5 error
7 error
8 error
9 error
10 error

 

  

 

posted @ 2023-02-11 12:13  小鲨鱼2018  阅读(26)  评论(0编辑  收藏  举报