How to convert multiple number ranges into sequence?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert multiple number ranges into sequence?
# 1  
Old 11-10-2012
How to convert multiple number ranges into sequence?

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
Code:
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

# 2  
Old 11-10-2012
awk solution:
Code:
awk 'NF>2{for(i=$1;i<=$2;i++) print i,$3}NF==2{print $1,$2}' FS="[- \t]*" OFS="\t" input.txt

# 3  
Old 11-10-2012
You are awesome, script works great, thanks
# 4  
Old 11-11-2012
also try:
Code:
awk "{NF>2?c=$2:c=$1;for(i=$1;i<=c;i++) print i,$NF}" FS="[- \t]*" OFS="\t"  infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert ip ranges to CIDR netblock

2 scripts to convert IP ranges to CIDR notation using awk, gawk or mawk. The scripts are much faster than using ipcalc and will return the same results. The first script is reliably compatible with awk, gawk and mawk but is over 3 times as slow as the second script which is reliably compatible with... (38 Replies)
Discussion started by: azdps
38 Replies

2. Shell Programming and Scripting

Convert ip ranges to CIDR netblocks

Hi, Recently I had to convert a 280K lines of ip ranges to the CIDR notation and generate a file to be used by ipset (netfilter) for ip filtering. Input file: 000.000.000.000 - 000.255.255.255 , 000 , invalid ip 001.000.064.000 - 001.000.127.255 , 000 , XXXXX 001.000.245.123 -... (10 Replies)
Discussion started by: ripat
10 Replies

3. Shell Programming and Scripting

Print root number between min and max ranges

Hi to all, Please help on the following problem, I'm not where to begin, if awk or shell script. I have pairs of ranges of numbers and I need to find the root or roots of ranges based on min Range and Max ranges Example #1: If min range is 120000 and max ranges 124999, it means that are... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

4. Shell Programming and Scripting

Convert a DNA sequence into Amino Acid

I am trying to write a bash script that would be able to read DNA sequences (each line in the file is a sequence) from a file, where sequences are separated by an empty line. I am then to find the amino acid that these DNA sequences encode per codon (each group of three literals.) For example, if I... (3 Replies)
Discussion started by: faizlo
3 Replies

5. Shell Programming and Scripting

Print numbers between two number ranges

Hi, I have a list.txt file with number ranges and want to print/save new all.txt file with all the numbers and between the numbers. == list.txt == 65936 65938 65942 && 65943 65945 ... (7 Replies)
Discussion started by: AK47
7 Replies

6. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

7. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

8. Shell Programming and Scripting

Need Help with function that has multiple ranges

I have a problem that I cant figure out what to do in this function i need it to count multiple ranges like 0 10, 5 10, 1 100. I know that my counter needs to be outside the function and that it needs to be set to the lowest numbered positional parameter but thats were I am having trouble if... (6 Replies)
Discussion started by: Emin_Em
6 Replies

9. Shell Programming and Scripting

Number count per number ranges

Hi, I have a question here that need to get advise from all of you. Let say I have a set of data 12347777 12359899 12347677 12360090 12347688 12359979 12359009 12367022 12346677 I need to count the number that appear in each numbering ranges and the output is like below: Prefix ... (5 Replies)
Discussion started by: shirleyeow
5 Replies

10. Shell Programming and Scripting

Finding number ranges using grep

Is it possible for me to find numbers in a file by a range using grep? like cat data | cut -f1 | grep <info> Im trying to find information and extract every amount that is less than a number (ie less than 75 or whatever) Is this possible? (2 Replies)
Discussion started by: DKNUCKLES
2 Replies
Login or Register to Ask a Question