Finding the Overlap


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the Overlap
# 1  
Old 09-24-2015
Finding the Overlap

Hi Help,
I am trying to find a overlap zone by compraing th etwo files which is printed below.

File-1 is ---
Code:
1011 234
2967 787
235 900
435 654

File 2 is ---
Code:
1211 456
595 678
546 678
2967 787

I would like to have a o/p which just read
Code:
2967 787

,'comm' doesn't seem to do the trick. Is there a way we can script it?

Thanks,
# 2  
Old 09-24-2015
For that simple scenario, try
Code:
grep -f file2 file1
2967 787


Last edited by RudiC; 09-24-2015 at 12:52 PM..
This User Gave Thanks to RudiC For This Post:
# 3  
Old 09-24-2015
Thanks a lot Rudi. Unfortunately, it takes ages for files which has say 1000's of records.
# 4  
Old 09-24-2015
Code:
awk 'NR==FNR {T[$0]; next} $0 in T' file1 file2
2967 787

These 2 Users Gave Thanks to RudiC For This Post:
# 5  
Old 09-24-2015
Hi Rudi,
Your script worked charm. Could you please explain what you did?
# 6  
Old 09-24-2015
It first reads file1 (identified by NR==FNR) into the associative array T. If then a line from file2 is found in the T indices, the line is printed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Overlap by two columns

Hi, I want to overlap two files based on two columns in each files. Here I'm overlapping the first two columns of the first file with columns 3 &4 of the second file (Bolded) to get the common lines. File1 ESR1 1 15 ggtga ESR1 7 18 tgcagt FOXA1 3 10 gtgat FOXA1 10 20 tgacc File2... (1 Reply)
Discussion started by: JJ001
1 Replies

2. Shell Programming and Scripting

finding first >

I want to erase some php code between a <? and a ?> in HTML containing a keyword, the problem is it finds the last > and wipes out everything before it how do i specify for it to stop searching after the first >? perl -i -p0e 's/<\?php.*keyword.*\?>//s' there's many lines of php code... (2 Replies)
Discussion started by: vanessafan99
2 Replies

3. Red Hat

Partition Overlap

I have just purchased a new server running RHELS R6 from a well known supplier. The OS came pre-installed so I (as a previous almost identical server) just finished off the install. I have just been extending one of the partitions and noticed an overlap. Filesystem Size Used Avail... (5 Replies)
Discussion started by: zetex
5 Replies

4. Solaris

Veritas VxVm 3.2 - Cannot unrelocate subdisk due to overlap with existing subdisks

Hi all, New to this forum as well as the world of Veritas Volume Manager. My client is using VxVM 3.2. We just changed one of the disk which is under veritas control. I used the appropriate options in vxdiskadm to replace this failed disk. Now when I am trying to unrelocate subdisks back to the... (0 Replies)
Discussion started by: rajan_g4
0 Replies

5. Shell Programming and Scripting

Awk Overlap

Based on input1 specific key (column1, 4 and 5) take the values (column 2 and 3) overlap with input2. And Specify names based on output. input1 a1 100 200 E1 ABC a1 300 400 E2 ABC a1 500 600 E3 ABC a2 100 200 E1 CDE a2 300 400 E2 ... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

Complex overlap and naming of 2 input files - Awk

for every specific $1,$2 check the values ($2,$3) of their E ot I of input1 and overlap with input2. Specify names based on output. ####### if middle value is missing name them "SE" if first value is missing name them "AFE" if last value is missing name them "ALE" if 2 middle values are... (1 Reply)
Discussion started by: ruby_sgp
1 Replies

7. Shell Programming and Scripting

multiple processes overlap

Hello I've got a script that creates multiple processes, in ksh, to bcp out 6 tables at a time. In the script, we write messages to the log to show our progress; most of the time, the log messages are nice and neat with one per line, like they should be. But every once in awhile, at random, the... (2 Replies)
Discussion started by: stonemonolith
2 Replies

8. Shell Programming and Scripting

Finding Overlap between two sets of data

Hi everyone, I posted this earlier, but the idea changed since then and I figured it would make more sense if I repost with a clearer idea in hopes someone can help me out. I have two lists of data in file1 and file 2 file1 (tab separated - column1 column2 column 3) 1 91625106 ... (1 Reply)
Discussion started by: labrazil
1 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question