How to use awk in this situation

how to change this file

335
339
666665
666668

to this result

335
336
337
338
339
666665
666666
666667
666668

explain: between two numbers with the same length, it will push through the missing number to make it numerical in ascending order. Many thanks

-1
source share
2 answers

I believe that this does what you want.

awk 'alen==length($1) {for (i=a;i<=$1;i++) print i}; {a=$1; alen=length(a); if (a==(i-1)) {a++}}'

When alen(length a) coincides with the length of the current linear cycle between aand $1, returns all missing values.

a $1, alen a, ( a i - 1), a ( 335, 339, 350 339).

@fedorqui .

: , , (, , @JohnB):

awk '{f=0; if (alen==length($1)) {for (i=a;i<=$1;i++) print i} else {f=1}} {a=$1; alen=length(a)} a==(i-1){a++} f{print; a++}'

, , .

: , , :

335
339
340
345
3412
34125
666665
666668
+6

:

$ awk 'NR%2 {a=$1; next} $1>a {for (i=a;i<=$1;i++) print i}' file
335
336
337
338
339
666665
666666
666667
666668

, , :)

  • NR%2 {a=$1; next} NR n umber r ecord ( ), NR%2 1, NR 2. , a . next .
  • $1>a {for (i=a;i<=$1;i++) print i} ( ), , , , , .
+3

All Articles