# How to convert multiple number ranges into sequence?

**URL:** <https://community.unix.com/t/how-to-convert-multiple-number-ranges-into-sequence/319719>\
**Category:** Shell Programming and Scripting\
**Created:** [November 10, 2012, 9:37pm UTC](https://community.unix.com/t/how-to-convert-multiple-number-ranges-into-sequence/319719 "2012-11-10T21:37:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcue25](https://community.unix.com/letter_avatar/jcue25/32/5_5575768a8748004e209b776fc1b2916d.png) [@jcue25](https://community.unix.com/u/jcue25)\
**Post date:** [November 10, 2012, 9:37pm UTC](https://community.unix.com/t/how-to-convert-multiple-number-ranges-into-sequence/319719/1 "2012-11-10T21:37:33Z")

</div>

Looking for a simple way to convert ranges to a numerical sequence that would assign the original value of the range to the individual numbers that are on the range.  
Thank you

```nohighlight
given data

13196-13199 0
13200 4
13201 10
13202-13207 3
13208-13210 7

desired output

13196 0
13197 0
13198 0
13199 0
13201 10
13202 3
13203 3
13204 3
13205 3
13206 3
13207 3
13208 7
13209 7
13210 7

```

---

<div class="post-metadata">

**Author:** ![mirni](https://community.unix.com/letter_avatar/mirni/32/5_5575768a8748004e209b776fc1b2916d.png) [@mirni](https://community.unix.com/u/mirni)\
**Post date:** [November 10, 2012, 9:48pm UTC](https://community.unix.com/t/how-to-convert-multiple-number-ranges-into-sequence/319719/2 "2012-11-10T21:48:36Z")

</div>

awk solution:

```nohighlight
awk 'NF>2{for(i=$1;i<=$2;i++) print i,$3}NF==2{print $1,$2}' FS="[- \t]*" OFS="\t" input.txt

```

---

<div class="post-metadata">

**Author:** ![jcue25](https://community.unix.com/letter_avatar/jcue25/32/5_5575768a8748004e209b776fc1b2916d.png) [@jcue25](https://community.unix.com/u/jcue25)\
**Post date:** [November 10, 2012, 10:32pm UTC](https://community.unix.com/t/how-to-convert-multiple-number-ranges-into-sequence/319719/3 "2012-11-10T22:32:22Z")

</div>

You are awesome, script works great, thanks

---

<div class="post-metadata">

**Author:** ![rdrtx1](https://community.unix.com/user_avatar/community.unix.com/rdrtx1/32/2721_2.png) [@rdrtx1](https://community.unix.com/u/rdrtx1)\
**Post date:** [November 11, 2012, 10:32am UTC](https://community.unix.com/t/how-to-convert-multiple-number-ranges-into-sequence/319719/4 "2012-11-11T10:32:07Z")

</div>

also try:

```nohighlight
awk "{NF>2?c=$2:c=$1;for(i=$1;i<=c;i++) print i,$NF}" FS="[- \t]*" OFS="\t" infile

```
