Please help on the following problem, I'm not where to begin, if awk or shell script.
I have pairs of ranges of numbers and I need to find the root or roots of ranges based on min Range and Max ranges
Example #1:
If min range is 120000 and max ranges 124999, it means that are contained numbers of the form 12XYYY, where X= 0-4 and Y=0-9,
then the roots for this pair of ranges are 120, 121, 122, 123 and 124 since between those ranges only will be numbers that begin with that
roots.
Example #2:
If min range = 200000 and max range = 299999, then it means that the numbers are of the form 2XXXXX where X=0-9 and there is only one root
that is 2
Example #3:
If min range = 570000 and max range = 579999, then it means that the numbers are of the form 57XXXX where X=0-9 and there is only one root
that is 57
The input is:
Min-Range Max Range
000000 999999
100000 199999
140000 199999
300000 699999
---------- Post updated at 12:32 ---------- Previous update was at 10:54 ----------
Howsoever, try
awk '
NR > 1 {DELTA = $2 - $1
n=split (DELTA, T, "")
for (i=1; i<=n; i++) if (T == "9") break
B = 0 + substr ($1, 1, length($1) - length(DELTA) + i - 1)
E = 0 + substr ($2, 1, length($2) - length(DELTA) + i - 1)
for (i=B; i<=E; i++) print i
}
' file
0
1
14
15
16
17
18
19
3
4
5
6
120
121
122
123
124
2
57
, including your examples #1 - #3 into the range file.
---------- Post updated at 12:46 ---------- Previous update was at 12:32 ----------
Handling of the first range line (field 1 being "000000") needs some special treatment; insert if (substr($1,1,1)=="0") {print 0; $1="1" substr($1,2)} just before DELTA is calculated.
Thanks so much for you help. I've tried your code and I think I can handle the input in order to avoid ranges beginning with 0, so the extra code before DELTA is not needed to make it simpler.