numeric range comparisons


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting numeric range comparisons
# 1  
Old 07-31-2008
numeric range comparisons

I have two files.And a sort of matrix analysis.

Both files have a string followed by two numbers:


File 1:
A 2 7
B 3 11
C 5 10

......
File 2:
X 1 10
Y 3 5
Z 5 9

What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in the first file falls between or is equal to those numbers in the second file.

e.g. print our:

X 1 10: A_first A_second B_first C_first C_second
Y 3 5: B_first C_second
Z 5 9: A_second C_first

My general idea was to open 3 arrays from the 1st file and use an 'if' comparison to the values in the second file but I really don't know what I'm doing.

Thank you for any help. Smilie
# 2  
Old 07-31-2008
What do you want for output?
# 3  
Old 07-31-2008
Output should be something to indicate the string in File 1 and which number(s) first second or both in the line with that string have hit appended to the end of the line in File 2

e.g.

X 1 10: A_2 A_7 B_3 C_5 C_10
Y 3 5: B_3 C_5
Z 5 9: A_7 C_5
# 4  
Old 08-01-2008
BTTT

Ok I really have no idea what I'm doing but I'm trying things. I need to figure out how to push all 3 strings through the array at one time:

awk '
NR==FNR{
a[NR]=$0
next
}
{
for(h=1;h<NR;h++)
for(i=1;i<NR;i++)
for(j=1;j<NR;j++)

print $1, $2, $3 ":" if ($2 =< a[i] =< $3) print a[h] "_" a[i] if ($2 =< a[j]=<$3) print a[h] "_" a[j]
}
' infile1 infile2 > outfile
# 5  
Old 08-04-2008
Bttt for this week.

I guess I'll need to do sometprint $1, $2, $3 ":" if ($2 < a[i] && a[i]=< $3) print a[h] "_" a[i] if ($2 < a[j] && a[j]<$3) print a[h] "_" a[j]
}
' infile1 infile2 > outfilehing like:

Can anyone help me figure out how to pass more than one string through the loop array??

Thanks.
# 6  
Old 08-05-2008
Somehow this just sounds like you would end up with a different and easier problem if you thought about it a little bit. What is it that you are trying to accomplish, on a higher level of abstraction?
# 7  
Old 08-05-2008
I'm trying to figure out how to push 2 (or more) strings through an array at the same time. So that I can track a name and number(s).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File comparisons

Hi all, I want to compare two files based on column value Kindly help me a.txt 123,ABCD 456,DEF 789,SDF b.txt 123,KJI 456,LMN 321,MJK 678,KOL Output file should be like Common on both files c.txt 123,ABCD,KJI (8 Replies)
Discussion started by: aaysa123
8 Replies

2. Shell Programming and Scripting

Zipping files by numeric name range

Hi there, Not being too up on bash shell programming at this point, could anyone throw me a bone about how to zip up a set of numerically-named files by range? For example, in a folder that contains files 1.pdf through 132000.pdf, I'd like to zip up just those files that are 50000.pdf and... (6 Replies)
Discussion started by: enwood
6 Replies

3. Shell Programming and Scripting

Generate Regex numeric range with specific sub-ranges

hi all, Say i have a range like 0 - 1000 and i need to split into diffrent files the lines which are within a specific fixed sub-range. I can achieve this manually but is not scalable if the range increase. E.g cat file1.txt Response time 2 ms Response time 15 ms Response time 101... (12 Replies)
Discussion started by: varu0612
12 Replies

4. Shell Programming and Scripting

String comparisons

Can someone please tell me what is wrong with this stings comparison? #!/bin/sh #set -xv set -u VAR=$(ping -c 5 -w 10 google.com | grep icmp_req=5 | awk '{print $6}') echo I like cookies echo $VAR if "$VAR" == 'icmp_req=5' then echo You Rock else echo You Stink fiThis is the error.... (6 Replies)
Discussion started by: cokedude
6 Replies

5. Shell Programming and Scripting

Awk numeric range match only one digit?

Hello, I have a text file with lines that look like this: 1974 12 27 -0.72743 -1.0169 2 1.25029 1974 12 28 -0.4958 -0.72926 2 0.881839 1974 12 29 -0.26331 -0.53426 2 0.595623 1974 12 30 7.71432E-02 -0.71887 3 0.723001 1974 12 31 0.187789 -1.07114 3 1.08748 1975 1 1 0.349933 -1.02217... (2 Replies)
Discussion started by: meridionaljet
2 Replies

6. Programming

Perl : Numeric Range Pattern Matching

hi Experts just wondering if you can help me check a number between a specific range if i have an ip address , how can i say the valid number for ip between 1 to 254 something like this if ($ip ) =~ /.../ { } what the pattern i need to type thanks (3 Replies)
Discussion started by: doubando
3 Replies

7. Shell Programming and Scripting

Count occurences of a numeric string falling in a range

Dear all, I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter. INPUT: 1.dat 1.3 2.16 0.34 ...... 2.dat 1.54 0.94 3.13 ..... ... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

8. Shell Programming and Scripting

awk to match a numeric range specified by two columns

Hi Everyone, Here's a snippet of my data: File 1 = testRef2: A1BG - 13208 13284 AAA1 - 34758475 34873943 AAAS - 53701240 53715412File 2 = 42MLN.3.bedS2: 13208 13208 13360 13363 13484 13518 13518My awk script: awk 'NR == FNR{a=$1;next} {$1>=a}{$1<=a}{print... (5 Replies)
Discussion started by: heecha
5 Replies

9. UNIX for Dummies Questions & Answers

Find and Replace random numeric value with non-numeric value

Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is: 1702938475,SNU022,201004 the first 10 numbers always begin with 170 (6 Replies)
Discussion started by: Bahf1s
6 Replies

10. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies
Login or Register to Ask a Question