unix - Merge two multi-column files based on one common column -


i have 2 tab-separated columns want merge based on common column. example:

file 1:

abandoning  0   v abandonment 0   n abandonments    0   n abandons    0   v abducted    0   v abduction   0   n 

file 2:

abandonment abducted abduction abound abounds abundance abundant accessable 

i want merge these files third file has empty value if information not available.

file 3 (desired result):

abandoning  0   v abandonment 0   n abandonments    0   n abandons    0   v abducted    0   v abduction   0   n abound abounds abundance abundant accessable 

i have been looking around here , here , here. far, closest thing have seen this:

awk '{a[$1]=a[$1] fs $2} end {for (i in a) print a[i]}' origfile.txt tomerge.txt | sort > merged_dict.txt  

however, results not include third column information. result obtain is:

abandoning 0 abandonment 0  abandonments 0 abandons 0 abducted 0  abduction 0  abound  abounds  abundance  abundant  accessable  

any hints going wrong?

you, can awk there tool if files sorted

$ join -a1 -a2 file1 file2  abandoning 0 v abandonment 0 n abandonments 0 n abandons 0 v abducted 0 v abduction 0 n abound abounds abundance abundant accessable 

here awk solution

$ awk 'nr==fnr{a[$0];next} $1 in a{delete a[$1]}1; end{for(k in a) print k}' file2 file1 |    sort 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -