Split a numeric into a difference of 100

Hi,

My input file is like this

chr1 100 700
chr2 800 900
chr3 900 1100

Note: All my records have a column3 to column2 difference of 100 or more for sure.

Now, I would like to do the following tasks

  1. Split the file starting at column2 and incrementing 100 until the value in column3 is reached. If the difference is already 100, don't do anything, in this case, record 2.
chr1 100 200
chr1 201 300
chr1 301 400
chr1 401 500
chr1 501 600
chr1 601 700
chr2 800 900
chr3 900 1000
chr3 1001 1100
awk '{ for (i = $2; i < $3; i += 100) { print $1, (a[NR]++ ? i + 1 : i), i + 100 }'
1 Like

You could also do:

awk '{ print $1, $2, i=$2+100;while(i++<$3) print $1, i, i+=99}' infile