Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match two file using grep and awk 2

Status
Not open for further replies.

demis001

Programmer
Aug 18, 2008
94
0
0
US
I want to match two file using grep and awk. Here is Data1 and Data2. I want to get overlap only if the following is true:

$1(Data1)==$1(Data2) && $3(Data1)==4(Data2)
Data1:
I929_79_46226_x388 GCAAAGCACACGGCCTGC 10
I929_79_145232_x1 TAGCAGCGGGAACAGTTC 11

Data2:
I929_79_145232_x1 15 1..15 11 134452384 46542640..46542654 5.8 1.00 30.2 Plus / Plus
I929_79_145232_x1 15 1..15 3 199501827 171473603..171473617 5.8 1.00 30.2 Plus / Plus
I929_79_46226_x388 15 1..15 10 242951149 168261508..168261522 5.8 1.00 30.2 Plus / Plus
I929_79_145232_x1 15 1..15 2 242951149 226319033..226319047 5.8 1.00 30.2 Plus / Plus
I929_79_145232_x1 15 1..15 1 247249719 92080967..92080981 5.8 1.00 30.2 Plus / Plus
 
A starting point:
awk 'NR==FNR{a[$1","$3]=$0;next}$1","$4 in a{print a[$1","$4]"\t"$0}' Data1 Data2

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's a way to get what you want: This is my first post, so here's hoping I do this correctly...

for name in `awk 'NF == 3 {arr1[$1,$3] += 1}; NF > 3 {arr1[$1,$4] += 1}; END {for(i in arr1) if(arr1 > 1) print i}' data1 data2`

do

awk -v N=$name 'BEGIN{sub(/[\034]/,"",N)}; NF==3 && $1$3 == N; NF>3 && $1$4 ==N; END{print ""}' data1 data2

done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top