Creating a range out of a broken list

Hi all,

I am trying to create a file which has one or more ranges based on a file containing a long list. The problem is that the file which has this list is not continuous and is broken in many places. I will try to illustrate by an example:

The List File:
1
2
3
4
5
6
9
10
11
12
13
14
15
23
24
25
26

The range file which I am looking for should be like:
1-6
9-15
23-26

I am not sure on how to proceed about this. Can someone share some ideas on what could be of help.

Cheers,
rte

Something like this?

awk 'NR < 7 || (NR > 8 && NR <16) || (NR > 22 && NR < 27)' file

what is the criteria to make file?

Do you mean how to redirect the output to a file?

Hi,

Thanks for the replies.

Just to clarify further- The example I gave was just an example and it is not the actual file that I want to make a range of. The break in the list is arbitary and is not actually that the list has breaks at numbers 6,15, etc. The script should identify the breaks and should create the range accordingly.

I hope that clears things a bit.

Cheers,
rte

I was not clear as to what he is expecting in output. :slight_smile:
now he has clarfied it.