If col1 and col2 of any line in both of two files in two files match, col1 and col2


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers If col1 and col2 of any line in both of two files in two files match, col1 and col2
# 1  
Old 03-03-2013
If col1 and col2 of any line in both of two files in two files match, col1 and col2

I have two files, and I'm interested in the first two columns of each.

File1 compares set1 to set2 (column1 = set1 name, column2 = set2 name).
File2 compares set2 to set1 (column1 = set2 name, column2 =set1 name).

I want to print the set names (column values) that appear as pairs in both files.

File1
Quote:
ACYPI070094-PA_product:Pol m.174988_g.174988 84.7 28 254 11 61 72 72 -1
ACYPI46488-PA_product:GLE m.160140_g.160140 69.6 45 231 26 78 112 104 -1
ACYPI007564-PA_product:unc m.118328_g.118328 96.2 100 79 3 76 79 79 -1
ACYPI38332-PA_product:GLEA m.1442_g.1442 80.4 100 148 29 119 148 161 -1
File2
Quote:
m.180547_g.180547 ACYPI56734-PA_product:dyn 89.9 100 69 7 62 69 873 -1
m.180550_g.180550 ACYPI007994-PA_product:3-k 69.2 100 78 24 54 78 397 -1
m.180565_g.180565 ACYPI008535-PA_product:Sar 81.2 100 80 15 65 80 1023 -1
m.160140_g.160140 ACYPI46488-PA_product:GLE 75.4 81 169 33 104 138 305 -1
Output
Quote:
m.160140_g.160140 ACYPI46488-PA_product:GLE
Can anyone help me out with this? I don't know where to go after recognizing and sorting columns.
# 2  
Old 03-03-2013
Code:
$ awk ' NR == FNR { arr[$1$2]=1; next } arr[$2$1] {print $1, $2} ' file1 file2
m.160140_g.160140 ACYPI46488-PA_product:GLE

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

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

Comparing two one-line files and selecting what does not match

I have two files. One is consisting of one line, with data separated by spaces and each number appearing only once. The other is consisting of one column and multiple lines which can have some numbers appearing more than once. It looks something like this: file 1: 20 700 15 30 file2: 10... (10 Replies)
Discussion started by: maya3
10 Replies

3. Shell Programming and Scripting

Match string from two files and print line

Hi, I have been trying to find help with my issue and I'm thinking awk may be able to do it. I have two files eg file1.txt STRING1 230 400 0.36 STRING2 400 230 -0.13 STRING3 130 349 1 file2.txt CUFFFLINKS 1 1394 93932 . + STRING1 CUFFFLINKS ... (9 Replies)
Discussion started by: zward
9 Replies

4. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

5. Shell Programming and Scripting

Adding info to end of line if two columns match from files with different separators

I have two files (csv and vcf) which look exactly like this S1.csv func,gene,start,info "exonic","AL","2309","het" "exonic","NEF","6912","hom"S1.vcf ##fileinfo #CHROM POS ID INFO chr1 4567 rs323211 1/1:84,104,99 chr4 2309 rs346742 1/1:27,213,90 chr6 5834 ... (5 Replies)
Discussion started by: Sarah_19
5 Replies

6. Shell Programming and Scripting

Merging data from col 3 to col2 with awk or sed

Dear Friends, I have a file in which lists State and Phone numbers. Does anybody have a solution in which to take the data from col3 and place it on col2? AK 2988421640 9077467107 AK 2998266711 2069239034 AK 2983804242 2069239034 AK 2960407849 AK ... (3 Replies)
Discussion started by: liketheshell
3 Replies

7. Shell Programming and Scripting

List files only when a certain number of files match

Hi, I have many files named CCR20110720011001.CTRD CCR20110720011501.CTRD CCR20110720012001.CTRD CCR20110720012501.CTRD CCR20110720021001.CTRD ... (9 Replies)
Discussion started by: shadyfright
9 Replies

8. Shell Programming and Scripting

Awk - Count instances of a number in col1 and put results in a col2 (new) of diff file

I have 2 files as follows: filename1: : 6742 /welcome/mundial98_ahf1_404.htm 1020 6743 /welcome/mundial98_ahf1_404.htm 2224 6744 /welcome/mundial_ef1_404.htm 21678 6745 /welcome/mundial_if_404.htm 4236 6746 /welcome/mundial_lf1_404.htm 21678 filename2: 6746 894694763 1... (2 Replies)
Discussion started by: jontjioe
2 Replies

9. Shell Programming and Scripting

Replace a column with a value conditional on a value in col1

Hi, Perhaps a rather simple problem...? I have data that looks like this. BPC0013 ANNUL_49610 0 0 1 1 BPC0014 ANNUL_49642 0 0 2 1 BPC0015 ANNUL_49580 0 0 1 1 BPC0016 ANNUL_49596 0 0 2 1 BPC0017 VULGO_49612 0 0 1 1 BPC0018 ANNUL_49628 0 0 1 1 BPC0019 ANNUL_49692 0 0 2 1 170291_HMG... (4 Replies)
Discussion started by: genehunter
4 Replies

10. UNIX for Dummies Questions & Answers

minus col1 and col2

my file looks like this: 101928 101943 101928 101944 101929 101943 101929 101943 101929 102044 i want to insert bc to get answer like this: 101928 101943 000015 101928 101944 000016 101929 101943 000013 101929 101943 000014 101929 102044 000115 total 000173 my... (3 Replies)
Discussion started by: tjmannonline
3 Replies
Login or Register to Ask a Question