linux 中 判断一组数据是否已经按照从小到大的顺序排列

 

001、

[root@PC1 test2]# ls
a.txt
[root@PC1 test2]# cat a.txt           ## 测试数据
1
2
3
4
5
6
7
8
9
10
[root@PC1 test2]# awk '{if(NR == 1) {a = $0}; if($0 < a) {print NR,"not order"}; a = $0}' a.txt     ## 判断程序

 

 

002、

[root@PC1 test2]# ls
a.txt
[root@PC1 test2]# cat a.txt        ## 测试数据,增加了相邻的相同的数值
1
2
2
2
3
4
4
4
5
6
7
8
9
10
[root@PC1 test2]# awk '{if(NR == 1) {a = $0}; if($0 < a) {print NR,"not order"}; a = $0}' a.txt       ## 判断程序

 

 

003、

[root@PC1 test2]# ls
a.txt
[root@PC1 test2]# cat a.txt       ## 测试数据, 增加了未正常排序的数值
1
2
2
2
3
4
4
6666
4
5
6
7
8888777
8
9
10
[root@PC1 test2]# awk '{if(NR == 1) {a = $0}; if($0 < a) {print NR,"not order"}; a = $0}' a.txt   ## 判断程序
9 not order
14 not order

 

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