Values between ranges


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Values between ranges
# 1  
Old 03-21-2012
Values between ranges

Hi,

I have two files

file1
Code:
chr1_22450_22500
chr2_12300_12350
chr1_34500_34550

file2
Code:
11000_13000
15000_19000
33000_44000

If the file 1 ranges fall between file2 ranges then assign the value of file2 in column 2 to file1

output:
Code:
chr2_12300_12350  11000_13000
chr1_34500_34550   33000_44000

Thanks,
# 2  
Old 03-21-2012
Are all of the entries non-overlapping - or to say it another way: Can you reuse some lines from file2?
# 3  
Old 03-22-2012
Yes, we can reuse the file2... Just we need to see if file1 ranges are falling between file2 ranges or not..
# 4  
Old 03-22-2012
Hi, try:
Code:
awk -F_ 'NR==FNR{R[$1]=$2;next} {for(i in R)if(i<=$2 && R[i]>=$3)print $0,i FS R[i]}' file2 file1

# 5  
Old 03-22-2012
Hi,

The code does not work..

Thanks,
# 6  
Old 03-22-2012
Hi.

Quote:
Originally Posted by Diya123
The code does not work.
If that is indeed what you meant, then consider:
Quote:
I've never seen the message "errors out" or "doesn't work" printed by any computer software yet people asking for help persist in claiming that is the result that they got.

Programmers spend their time (some not enough, maybe) printing clear error messages to tell you what you are doing wrong.

From: comp.os.linux.misc
When you provide useful information, you are more likely to receive solutions quickly and on-point.

Best wishes ... cheers, drl

Last edited by drl; 03-22-2012 at 02:45 PM.. Reason: Typo.
This User Gave Thanks to drl For This Post:
# 7  
Old 03-22-2012
Hi,

Sorry. I dint mean to be harsh or say it dint work.. When I used the code provided it just executed with no error message and no output. I understand that this forum is to help others and people try to take out some time from their busy schedule to do this..

Let me explain my question more clearly..

Of the two files which I have I am trying to check if my file1 positions fall between file 2 ranges. If so I need to assign the file 2 position to my file1.

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Derivation of values falling on date ranges

Hi Guys, I am having below tables used in oracle bal ID BALANCE BAL_DATE 1 -11.71 01-JAN-05 00.00.00 1 -405.71 02-JAN-05 00.00.00 1 -760.71 03-JAN-05 00.00.00 ref_table PRODUCT EFF_FROM_DATE EFF_TO_DATE TYPE MIN_AMT MAX_AMT CHARGE 12 01-JAN-05 00.00.00 01-JAN-06... (6 Replies)
Discussion started by: rohit_shinez
6 Replies

2. Shell Programming and Scripting

Sum values of specific column in multiple files, considering ranges defined in another file

I have a file (let say file B) like this: File B: A1 3 5 A1 7 9 A2 2 5 A3 1 3 The first column defines a filename and the other two define a range in that specific file. In the same directory, I have also three more files (File A1, A2 and A3). Here is 10 sample lines... (3 Replies)
Discussion started by: Bastami
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the values of two columns (given ranges)

Hi, I have a tab delimited text file with multiple columns. The second and third columns include numbers that have not been sorted. I want to extract rows where the second column includes a value between -0.01 and 0.01 (including both numbers) and the first third column includes a value between... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. IP Networking

Test for overlapping IP ranges

Greetings folks, I have a rather lengthy list of banned IP ranges in iptables. Initially it was constructed as a rather ad-hoc affair, then later I discovered a site which had IP Block By Country lists, and imported several into iptables. If possible, I'd like to be able to verify if the list... (0 Replies)
Discussion started by: putter1900
0 Replies

5. UNIX for Dummies Questions & Answers

Problem with ranges of numbers

Good day to everyone! So, let's start :) I have a file with a numbers in some ranges for example: 1 10 49 72 ... and this file need to transform to: 1 2 3 4 (14 Replies)
Discussion started by: shizik
14 Replies

6. HP-UX

Help reserving UID ranges?

We have recently merged 2 old systems onto a newer Itanium platform. As part of this work we merged the password files and assigned new UID's beginning from 1000. I have a user add script that admins can use to add a user, however this assigns the next available UIB (in the low 100's) rather than... (3 Replies)
Discussion started by: fulhamfcboy
3 Replies

7. UNIX for Dummies Questions & Answers

Need help filling in ranges

I have a list of about 200,000 lines in a text file that look like this: 1 1 120 1 80 200 1 150 270 5 50 170 5 100 220 5 300 420 The first column is an identifier, the next 2 columns are a range (always 120 value range) I'm trying fill in the values of those ranges, and remove... (4 Replies)
Discussion started by: knott76
4 Replies

8. Shell Programming and Scripting

date ranges

Hi, Please anyone help to achive this using perl or unix scripting . This is date in my table 20090224,based on the date need to check the files,If file exist for that date then increment by 1 for that date and check till max date 'i.e.20090301 and push those files . files1_20090224... (2 Replies)
Discussion started by: akil
2 Replies

9. Shell Programming and Scripting

Search values between ranges in File1 within File2

Hi people, I have 2 files, one with a list of non consecutive ranges (File1.txt), where each range begins with the value in column 1 and finishes with the value in column 2 in the same line, as can be seen above. 215312581156279 215312581166279 215312582342558 215312582357758... (4 Replies)
Discussion started by: cgkmal
4 Replies

10. Shell Programming and Scripting

awk to print mon and max values of ranges

HI all I'm trying to write an awk script to print the min and max value in a range(s) contained in another file - the range values are in $2 EG 114,7964,1,y,y,n 114,7965,1,y,y,n 114,7966,1,y,y,n 114,7967,1,y,y,n 114,7969,1,y,y,n 114,7970,1,y,y,n 114,7971,1,y,y,n 114,7972,1,y,y,n... (3 Replies)
Discussion started by: Mudshark
3 Replies
Login or Register to Ask a Question