Creating a range out of a broken list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a range out of a broken list
# 1  
Old 06-19-2009
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
# 2  
Old 06-19-2009
Something like this?

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

# 3  
Old 06-19-2009
what is the criteria to make file?
# 4  
Old 06-19-2009
Quote:
Originally Posted by rakeshawasthi
what is the criteria to make file?
Do you mean how to redirect the output to a file?
# 5  
Old 06-19-2009
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
# 6  
Old 06-19-2009
Quote:
Originally Posted by Franklin52
Do you mean how to redirect the output to a file?
I was not clear as to what he is expecting in output. Smilie
now he has clarfied it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

I need to find in a file a list of number where last two digit end in a range

I all I am tryng to find a way to sort a list of number in a file by the value of last two digit. i have a list like this 313202320388 333202171199 373202164587 393202143736 323202132208 353201918107 343201887399 363201810249 333201805043 353201791691 (7 Replies)
Discussion started by: rattoeur
7 Replies

2. Shell Programming and Scripting

Convert list of numbers to text range

Hi, I'd like to take a list of numbers (with a prefix) and convert to a range, for example: cn001 cn004 cn016 cn017 cn018 cn019 cn020 cn021 cn031 cn032 cn038 cn042 cn043 cn044 cn045 (5 Replies)
Discussion started by: chrissycc
5 Replies

3. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Shell Programming and Scripting

Using 'date' to list a range of dates

Hi guys, I have been trying to create a list of dates from a certain range, ie. range from 01011950 to 31122000 But when my below code reaches certain dates, it comes up with a; 'date: invalid date 'yyyy-mm-dd -d 1day' Sofar I have come up with the following, slow and ugly; ... (4 Replies)
Discussion started by: TAPE
4 Replies

5. Shell Programming and Scripting

List files with Date Range and Zip it

Hi all, I am using the below script which display the files in the folder with the date range we specify. I want to add extra functionality that, The listing files should be zipped using gzip. I tried to add exec gzip at the last line but it is not working. Suggestions please. ... (2 Replies)
Discussion started by: nokiak810
2 Replies

6. Shell Programming and Scripting

List/Range Todays Log.

Hi All, I am mediator Shell programmer, Just have an hands on experice :-), i am writing a shell scirpt to list logs of todays date from /var/log/messages. I need to ur kind help where if i run this script from cron. the script should filter todays logs only from /var/log/messages. Below... (4 Replies)
Discussion started by: anand.kulkarni
4 Replies

7. Shell Programming and Scripting

Create range from a list

Hello everyone, I am trying to create a script that will make a range or ranges based on a sorted list of numbers. Eg. If the list is like 1 2 3 4 5 6 7 12 13 14 15 The output range should be: 1-7 12-15 (9 Replies)
Discussion started by: run_time_error
9 Replies

8. UNIX for Dummies Questions & Answers

List-to-Range of Numbers

Hello, I have two columns with data that look like this: Col1 Col2 ------ ----- a 1 a 2 a 3 a 4 a 7 a 8 a 9 a 10 a 11 b 6 b 7 b 8 b 9 b 14 (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

9. UNIX for Dummies Questions & Answers

How to list file names in a certain date range using ls command?

Hi experts, I Need to print file names in a certain date range using ls:confused:. Please help me with any sample script. Thanks a lot in advance. Regards, Satish (4 Replies)
Discussion started by: satish.vutti
4 Replies

10. Shell Programming and Scripting

to get list of files of a perticular range of time

hi, how to list the files which has been created or accessed before 6 months thanks (1 Reply)
Discussion started by: useless79
1 Replies
Login or Register to Ask a Question