Overlap by two columns


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Overlap by two columns
# 1  
Old 04-11-2014
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
Code:
ESR1	1	15	ggtga
ESR1	7	18	tgcagt
FOXA1	3	10	gtgat
FOXA1	10	20	tgacc

File2
Code:
abcsd	34	ESR1	1	15
dfdf	55	ESR1	10	17
sdf	44	FOXA1	3	10
fdf	53	FOXA1	30	40

Output
Code:
ESR1	1	15	ggtga	abcsd	34	ESR1	1	15
FOXA1	3	10	gtgat	sdf	44	FOXA1	3	10

Thanks
# 2  
Old 04-11-2014
Welcome to Forums
Code:
$ cat file1
ESR1	1	15	ggtga
ESR1	7	18	tgcagt
FOXA1	3	10	gtgat
FOXA1	10	20	tgacc

Code:
$ cat file2
abcsd	34	ESR1	1	15
dfdf	55	ESR1	10	17
sdf	44	FOXA1	3	10
fdf	53	FOXA1	30	40

Code:
$ awk 'FNR==NR{A[$1 FS $2]=$0;next}(($3 FS $4) in A){print A[$3 FS $4],$0}' file1 file2

Output
Code:
ESR1	1	15	ggtga abcsd	34	ESR1	1	15
FOXA1	3	10	gtgat sdf	44	FOXA1	3	10

This User Gave Thanks to Akshay Hegde For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 --- 1011 234 2967 787 235 900 435 654 File 2 is --- 1211 456 595 678 546 678 2967 787 I would like to have a o/p which just read 2967 787,'comm' doesn't seem to do the... (5 Replies)
Discussion started by: Indra2011
5 Replies

2. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 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

Single command for add 2 columns and remove 2 columns in unix/performance tuning

Hi all, I have created a script which adding two columns and removing two columns for all files. Filename: Cust_information_1200_201010.txt Source Data: "1","Cust information","123","106001","street","1-203 high street" "1","Cust information","124","105001","street","1-203 high street" ... (0 Replies)
Discussion started by: onesuri
0 Replies

8. 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

9. 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
Login or Register to Ask a Question