matching the coordintaes between 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching the coordintaes between 2 files
# 1  
Old 10-06-2012
Data matching the coordintaes between 2 files

Hii
i have 2 files my file1 contains range of values in col 2 and col3. The second file contains the associated names with respect to that particular range i want to check whether values in first file fall with in the range of values in 2nd file if yes then i want to get the associated name as shown in example

file1

Code:
chr1 10 20
hu1 5 15
hu1 12 19
hu1 36 40
hu1 78 89
hu1 310 865
hu1 80 85

file2

Code:
chr1 1 30 xyz
hu1 35 45 ytg
hu1 70 90 ttf
hu1 300 920 opp

output
Code:
chr1 10 20 xyz 
hu1 5 15 xyz
hu1 12 19 xyz
hu1 36 40 ytg
hu1 78 89 ttf
hu1 310 865 opp
hu1 80 85 ttf

# 2  
Old 10-06-2012
Like this?
Code:
awk 'FNR==NR{val[$2,$3]=$4;next}
{for(i in val)
{
 split(i,temp,SUBSEP)
 if($2>=temp[1] && $3<=temp[2])
 {
  $0=$0 " " val[i]
  break
 }
}}1' file2 file1

# 3  
Old 10-06-2012
Thank you its working well
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

2. Shell Programming and Scripting

Matching two files per column

Hi, I hope somebody can help me with this problem, since I would like to solve this problem using awk, but im not experienced enough with this. I have two files which i want to match, and output the matching column name and row number. One file contains 4 columns like this: FILE1: a ... (6 Replies)
Discussion started by: Jenna.bos
6 Replies

3. Shell Programming and Scripting

matching two files

Hello, I need to match one file with another. The best would be to give an example. File 1 A 1 B 2 C 3 D 4 E 5 F 6 File 2 A 5 6 2 B 3 2 1 F 4 2 9 (1 Reply)
Discussion started by: gisele_l
1 Replies

4. UNIX for Dummies Questions & Answers

Matching corresponding columns in two different files

Hi to all, I have two separated files: FILE1 "V1" "V2" "V3" Mary James Nicole Robert Francisco Sophie Nancy Antony Matt Josephine Louise Rose Mark Simon Charles FILE2 "V1" "V2" "V3"... (2 Replies)
Discussion started by: eleonoral
2 Replies

5. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

6. Shell Programming and Scripting

Matching 2 files

Hi I am able to match two files (fileA and B) based on the first column using this line. awk -F"/t" 'NR == FNR { A = $0; next } A { print $0 FS A }' However I now need to match the two files (files A and B) based on two columns. On top of that, for those that dont match, I want it to... (1 Reply)
Discussion started by: phil_heath
1 Replies

7. Shell Programming and Scripting

Not matching files

Hi I need to check list of files aganinst a.txt and return those files which are not available in a.txt ls -lrt file1.txt file2.txt file3.txt a.txt ===== file1.txt file2.txt Expecting o/p file3.txt (3 Replies)
Discussion started by: akil
3 Replies

8. Shell Programming and Scripting

Matching 2 files

Hi, I am able to modify files (one file) but I have a hard time working with multiple files simultaneously. So I have two files. Basically I want to match two files based on certain columns. Both files are tab-seperated. File1 looks something like this: num1 89 george num4 78 ... (4 Replies)
Discussion started by: kylle345
4 Replies

9. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

10. Shell Programming and Scripting

Matching and combining two files

Hi, How can I match the first two fields of file2 against the first two fields of file1 and where they match combine the two lines. If the name (example-Aidan Rielly) is in file1 but not in file2 then just write the info from file1 to the combined output file. If the name (example-Silvia... (5 Replies)
Discussion started by: p3t3r
5 Replies
Login or Register to Ask a Question