假设我有一个像这样的文件
1
2
3
5
8
9
我想找出连续的订单:
consecutive order from 1 to 3
consecutive order from 5 to 6
等
答案 0 :(得分:0)
让我们调用包含数据的文件 / tmp / dataFile ,您可以使用awk执行此操作,如下所示:
awk 'NR==1{lowerBound=$1;upperBound=$1;next} $1 == upperBound+1 {upperBound=$1;next} {print "consecutive order from " lowerBound,"to", upperBound;lowerBound=$1;upperBound=lowerBound} END{print "consecutive order from " lowerBound,"to",upperBound}' /tmp/dataFile