To Create range of values

Hi,

I have a file with the below like values with integers only in sorted order (May or may not be in sequence)

Eg: File1.txt
-----------
1
2
3
4
5
6
.
.
.
.
.
10000

My requirement here is to create a range of values out put to a temp k
file based on the percentage that i input to the File1.txt .
Suppose if i execute the shell script with the 10(percentage) as input,my out put would look like this in temp file
1-1000
1001-2000
2001-3000
.
.
.
9001-10000

Please help me with script

hmm - what happens / do you want to happen if your percentage doesn't divide exactly into 100 in integer chunks e.g. 14. would you want:

1 - 1400
1401 - 2800
2801 - 4200
4201 - 5600
5601 - 7000
7001 - 8400
8401 - 9800

Or would you also want the 9801-10000 range ?

Assuming you're not too worried about this, and that as noted the last entry in your file is the largest then:

#  echo $(tail -1 infile) 10 | awk '{for (i=0;i<=100/$2;i++){t=$1*$2*i/100}}{for (j=1;j<=100/$2;j++){print t[j-1]+1,"-",t[j]}}'
1 - 1000
1001 - 2000
2001 - 3000
3001 - 4000
4001 - 5000
5001 - 6000
6001 - 7000
7001 - 8000
8001 - 9000
9001 - 10000

should get you headed in the right direction....HTH

Hi Tytalus,

Appreciate your response.

As you said i require the range 9801-10000 (Or would you also want the 9801-10000 range ?) and it is mandate also.

Thank you

---------- Post updated at 07:31 PM ---------- Previous update was at 06:19 PM ----------

Hi,

My integers are created in the below range with 2600 values ,and i inputted to the script sent by you with the below input and 50 as dividing factor

0000000433874674
.
.
.
.
.
0000000433877573

i end up in below result .

1 - 2.16939e+08
2.16939e+08 - 433877573

Now we have two requirements below.

1) We want to have the chunks even it is divided by 14 as you said in your earlier post
2) And we want to avoid the exponential parts as put up in the above example .

Thanks in Advance

aah - so they don't neccessarily start from 1...

urg.. ok following code snippet should point you in right lines:

#  echo "0000000433874674 0000000433877573 10" | awk '{for (i=0;i<100/$3;i++){t=($2-$1)*$3*i/100}}   {if (t<$1){t[i++]=$2-$1}}   {for (j=1;j<i;j++){printf("%d - %d\n",t[j-1]+1+$1,t[j]+$1)}}'
433874675 - 433874963
433874964 - 433875253
433875254 - 433875543
433875544 - 433875833
433875834 - 433876123
433876124 - 433876413
433876414 - 433876703
433876704 - 433876993
433876994 - 433877283
433877284 - 433877573

HTH

Hi Tytalus,

Appreciate ur response.

Some more requirements after executing your script are below .if you can help me out your script with the below requirements i would be very happy.

1) I want zeros also to be printed
2) i shouldn't have the space before and after the "-"

Eg: present o/p :433874675 - 433874963
Expected O/P: 0000000433874675-0000000433874963 (with zeros and no space before and after "-")