Compare intervals (columns) from two files (awk, grep, Perl?)
Hi dear users,
I need to compare numeric columns in two files. These files have the following structure.
K.txt (4 columns)
K.txt file's columns 3 and 4 are the starting and ending positions of an interval for each gene name in column 1.
S.txt (4 columns)
S.txt file's columns 2 and 3 are also intervals (but shorter than K.txt). Also S.txt file is larger than K.txt
These are the possible outcomes, (or intersections among the intervals):
S$3 <= K$3 (don't print to output)
S$2 <= K$3 AND S$3 >= K$3 (print to output)
S$2 >= K$3 AND S$3 <= K$4 (print to output)
S$2 <= K$4 AND S$3 >= K$4 (print to output)
S$2 >= K$4 (don't print to output)
output should have 2 columns (tab separated): first is column 4 from S.txt (S$4) and second is column 1 from K.txt (K$1). If there are multiple matches like in the example, they should be separated by commas.
Any suggestion will be very welcome.
Thank you!
Moderator's Comments:
Please use code tags when posting data and code samples!
Last edited by vgersh99; 01-17-2012 at 03:40 PM..
Reason: code tags, please!
Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns.
I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Hi,
I want to compare two columns from file1 with another two column of file2 and print matched and unmatched column like this
File1
1 rs1 abc
3 rs4 xyz
1 rs3 stu
File2
1 kkk rs1 AA 10
1 aaa rs2 DD 20
1 ccc ... (2 Replies)
Hi,
I want to compare the columns of two files excluding column 2 from both the files. I tried this awk command.
awk -F":" 'NR==FNR{++a;next} !(a)' file1.txt file2.txt
.
Example: File1.txt
123:09-15-2011:abc:123456
123:09-15-2011:abc:234567
123:09-15-2011:abc:345678
... (5 Replies)
Hi
I have file 1 like this:
file 2 is like this:
The files are tab separated. I want to search for the first column values of file 1 in the first column of file 2 and merge the 3rd column value of file 2 to the corresponding line on first file.
so the desired output is;
I tried following... (2 Replies)
Hello. I have two files. FILE1 was extracted from FILE2 and modified thanks to help from this post. Now I need to replace the extracted, modified lines into the original file (FILE2) to produce the FILE3.
FILE1
1466 55.27433 14.72050 -2.52E+03 3.00E-01 1.05E+04 2.57E+04
1467 55.27433... (1 Reply)
Hello,
I have not been able to find what I'm looking for via searching the forum. I could use some help with an awk script or one-liner to solve this simple problem.
I have two files. If $1 and $2 from file1 match $1 and $2 from file2, print the whole line from file2.
Example file1
... (2 Replies)
Folks I need your help cuz I've a file with 100,000 records that need to be compared against a passwd file (300) and then create a third one with the data in the first one and the passwd from the second one set in it.
The format of the first file is:
host xxxxxx "" 0,0 Closed control00/... (4 Replies)
Hello,
My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns:
File A: (tab-delimited)
PDB CHAIN Start End Fragment
1avq A 171 176 awyfan
1avq A 172 177 wyfany
1c7k A 2 7... (3 Replies)