unix - Comparison of two files with awk command -


i have got 2 files, file1 , file2, compared , put in file3.

file1:

red green blue red yellow pink orange 

file2:

domain1,red,- domain2,-,green domain3,blue,- domain4,yellow,pink domain5,grey,orange 

now need output follows in file3:

domain1,red domain2,green domain3,blue domain1,red domain4,yellow domain4,pink domain5,orange 

for each record in file1, if matched, needs produce $1 mandatory , matching value either $2 or $3 file2, if both($2,$3) matched, should in 2 records (single record do) "domain5,pink,orange".

i'm newbie awk command. please me achieve awk!

i have simple command not sufficing condition

awk 'nr==fnr{x[$1];next}($2,$3) in x' fs=',' file1 file2 >file3 

awk -f, 'begin{ofs=","}           nf>1 {s[$2]=s[$3]=$1;}           nf==1 {print s[$1],$1}' input2 input1 

output

domain1,red domain2,green domain3,blue domain1,red domain4,yellow domain4,pink domain5,orange 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -