查找差距序列号 [英] Finding gaps sequential numbers
问题描述
我不为生活所以请原谅我,如果它是一个简单的问题(或更复杂的比我想)做这个东西。我已经挖通过档案,发现有很多是接近技巧但作为一个新手,我不知道如何调整我的需要,或他们是远远超出我的理解。
I don’t do this stuff for a living so forgive me if it’s a simple question (or more complicated than I think). I‘ve been digging through the archives and found a lot of tips that are close but being a novice I’m not sure how to tweak for my needs or they are way beyond my understanding.
我有一些大的数据文件,我可以解析出生成坐标大多顺序
I have some large data files that I can parse out to generate a list of coordinate that are mostly sequential
5
6
7
8
15
16
17
25
26
27
我要的是空白的列表
What I want is a list of the gaps
1-4
9-14
18-24
我不知道的Perl,SQL或任何幻想,但我想也许可以做一些事情,会从下一个减去一个数。然后,我至少可以用grep的输出,其中差异无1或-1,并与合作得到的空白。
I don’t know perl, SQL or anything fancy but thought I might be able to do something that would subtract one number from the next. I could then at least grep the output where the difference was not 1 or -1 and work with that to get the gaps.
推荐答案
通过的 AWK :
awk '$1!=p+1{print p+1"-"$1-1}{p=$1}' file.txt
说明
-
$ 1
是当前输入行的第一列 -
P
是最后一行的previous值 - 所以
($ 1 = P + 1!)
是一个条件:如果$ 1
低于$ P $不同pvious值+1,则: - 这部分被执行:
{打印P + 1 - $ 1-1}
:打印previous值+1,在-
字符握拳柱+ 1 -
{P = $ 1}
为每个行执行:P
被分配到当前第1列 $1
is the first column from current input linep
is the previous value of the last line- so
($1!=p+1)
is a condition : if$1
is different than previous value +1, then : - this part is executed :
{print p+1 "-" $1-1}
: print previous value +1, the-
character and fist columns + 1 {p=$1}
is executed for each lines :p
is assigned to the current 1st column
explanations
这篇关于查找差距序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!