How to create individual entries from a range of numbers?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create individual entries from a range of numbers?
# 1  
Old 12-04-2013
How to create individual entries from a range of numbers?

I want to create entries based on the series as in examples below:


Input:

Code:
2dat3 grht-5&&-15
3dat3 grht-16&&-30
4dat3 ftht-4&&-12
5sat3 ftht-16&&-20


Output:

Code:
2dat3	grht-5
2dat3	grht-6
2dat3	grht-7
2dat3	grht-8
2dat3	grht-9
2dat3	grht-10
2dat3	grht-11
2dat3	grht-12
2dat3	grht-13
2dat3	grht-14
2dat3	grht-15
3dat3	grht-16
3dat3	grht-17
3dat3	grht-18
3dat3	grht-19
3dat3	grht-20
3dat3	grht-21
3dat3	grht-22
3dat3	grht-23
3dat3	grht-24
3dat3	grht-25
3dat3	grht-26
3dat3	grht-27
3dat3	grht-28
3dat3	grht-29
3dat3	grht-30
4dat3	ftht-4
4dat3	ftht-5
4dat3	ftht-6
4dat3	ftht-7
4dat3	ftht-8
4dat3	ftht-9
4dat3	ftht-10
4dat3	ftht-11
4dat3	ftht-12
5sat3	ftht-16
5sat3	ftht-17
5sat3	ftht-18
5sat3	ftht-19
5sat3	ftht-20

# 2  
Old 12-04-2013
So, what have you tried so far and where are you getting stuck?

It seems that you need to recognise the values you have then starting with the first value in the range, loop through displaying the required output and adding one to the counter before you go round and see if you have reached the end value.


You would also be better to say what tools you prefer to work in and your OS version (name and release level) in case there are any suggestions that rely on or could exploit the variant that you have.




Robin
# 3  
Old 12-04-2013
I will like to use awk
# 4  
Old 12-04-2013
Try :

this works for given input in #1
Code:
$ awk -F'[-&&]' '{for(i=$2;i<=$NF;i++)print $1"-"i}' Input

These 2 Users Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 12-04-2013
It worked, Thanks!
# 6  
Old 12-04-2013
Wow! Could you explain a little please Akshay Hegde? I'd love to understand it a bit better.


Thanks,
Robin
# 7  
Old 12-04-2013
Quote:
Originally Posted by rbatte1
Wow! Could you explain a little please Akshay Hegde? I'd love to understand it a bit better.


Thanks,
Robin

I just used simple for loop
for(INITIALIZATION; CONDITION; AFTERTHOUGHT)

for example :
Code:
2dat3 grht-5&&-15

-&& ---> Field Separator
2dat3 grht ---> field1 $1
5---> Field2 $2 that is i start
15-->last Field $NF is i end
for(i=5;i<=15;i++)print $1"-"i-->increment i till 15 and print $1 and i
This User Gave Thanks to Akshay Hegde For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print range of numbers

Hi I am getting an argument which specifies the range of numbers. eg: 7-15 Is there a way that i can easily (avoiding loop) print the range of number between and including the specified above. The above example should translate to 7,8,9,10,11,12,13,14,15 (3 Replies)
Discussion started by: tostay2003
3 Replies

2. Shell Programming and Scripting

Unique entries based on a range of numbers.

Hi, I have a matrix like this: Algorithm predicted_gene start_point end_point A x 65 85 B x 70 80 C x 75 85 D x 10 20 B y 125 130 C y 120 140 D y 200 210 Here there are four tab-separated columns. The first column is the used algorithm for prediction, and there are 4 of them A-D.... (8 Replies)
Discussion started by: flyfisherman
8 Replies

3. UNIX for Dummies Questions & Answers

Grep for a range of numbers?

I am trying to extract specific information from a large *.sam file (it's originally 28Gb). I want to extract all lines that are on chr3 somewhere in the range of 112,937,439-113,437,438. Here is a sample line from my file so you can get a feel for what each line looks like: seq.4 0 ... (8 Replies)
Discussion started by: genGirl23
8 Replies

4. Shell Programming and Scripting

awk? create similarity matrix by calculating overlaps between sets comprising of individual parts

Hi everyone I am very new at awk and to me the task I need to get done is very very challenging... Nevertheless, after admiring how fast and elegant issues are being solved here I am sure this is my best chance. I have a 2D data file (input file is a plain tab-delimited text file). The first... (1 Reply)
Discussion started by: stonemonkey
1 Replies

5. Shell Programming and Scripting

grep for a range of numbers

Dear Friends, I want to know how to grep for the lines that has a number between given range(start and end). I have tried the following sed command. sed -n -e '/20030101011442/,/20030101035519/p' However this requires both start and end to be part of the content being grepped. However... (4 Replies)
Discussion started by: tamil.pamaran
4 Replies

6. UNIX for Dummies Questions & Answers

Frequency of a range of numbers

Hello, I have a column where there are values from 1 to 150. I want to get the frequency of values in the following ranges: 1-5 6-10 11-15 .... .... .... 146-150 How can I do this in a for loop? Thanks, Guss (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

7. 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

8. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

9. UNIX for Dummies Questions & Answers

Using grep on a range of numbers

Hi im new to unix and need to find a way to grep the top 5 numbers in a file and put them into another file. For example my file looks like this abcdef 50000 abcdef 45000 abcdef 40000 abcdef 35000 abcdef 30000 abcdef 25000 abcdef 20000 abcdef 15000 abcdef 10000 and so on... How can... (1 Reply)
Discussion started by: ProgChick2oo9
1 Replies

10. Shell Programming and Scripting

grep numbers range

I want to grep a range of numbers in a log file. My log file looks like this: 20050807070609Z;blah blah That is a combination of yr,month,date,hours,minutes,seconds. I want to search in the log file events that happened between a particular time. like between 20050807070000 to 20050822070000... (1 Reply)
Discussion started by: azmathshaikh
1 Replies
Login or Register to Ask a Question