I have a text file that contains the following data. For example, aa.txt has some numbers. I need to extract the continuous numbers(minimum 3 numbers) from it.How can I do this with awk?
awk '
BEGIN {
c = 1
}
{
A[NR] = $1
}
END {
for ( i = 1; i < NR; i++ )
{
d = A[i+1] - A
F = FILENAME
sub ( /\.txt/, "_" c ".txt", F )
if ( d == 1 )
{
printf "%d\n", A > F
f = 1
}
if ( f && d != 1 )
{
printf "%d\n", A > F
f = 0
c += 1
}
}
}
' aa.txt
arr=[]
with open("a.txt") as file:
for line in file:
line=line.replace("\n","")
if not arr:
arr.append(line)
elif int(arr[-1])+1==int(line):
arr.append(line)
else:
if len(arr)>=3:
print("\n".join(arr))
print("")
arr=[line]
if len(arr)>=3:
print("\n".join(arr))