Q:

How to Split the number into a specific range(between 1000) in unix

For example if the number is 4569.
i need the output as 
1 - 1000
1001 - 2000
2001 - 3000
3001 - 4000
4000 - 4569

I wrote the logic in JAVA for this now but I am migrating my code to UNIX. Is there any single liner to split the numbers with specific range?

A:

There may be a one-liner with awk. If you have a recent bash you could use bash arithmetics. It's not as fast tho.
sample.sh
#!/bin/bash

(( max = $1 ))
(( num = 0 ))
echo "going for " $max

while (( max >= num )); do
    (( prev = num + 1 ))
    (( num = prev + 999 ))
    if (( num >= max )); then
            echo $prev "-" $max
    else
            echo $prev "-" $num
    fi
done

which prints
$ ./sample.sh 4569
going for  4569
1 - 1000
1001 - 2000
2001 - 3000
3001 - 4000
4001 - 4569

You can modify it accordingly.

