Merge files based on both common and uncommon rows

Hi,

I have two files A (2190 rows) and file B (1100 rows). I want to merge the contents of two files based on common field, also I need the unmatched rows from file A

file A:

ABC
XYZ
PQR

file B:

>LMN|chr1:11000-12456[+]: ['CCATYVCY','ACGTGCDT']
>ABC|chr15:176578-187678[-]: ['CCTGCGT']
>PQR|chr3:14567-15866[+]: ['CCTYHGV','TLKJNWYT',TTGCDGT']

output

ABC chr15:176578-187678[-] ['CCTGCGT']
XYZ
PQR  chr3:14567-15866[+]  ['CCTYHGV','TLKJNWYT',TTGCDGT']

I am aware of how to get the common columns, buy not sure how to also report the unmatched rows from file A

Thanks

Try something like:

awk -F\| 'NR==FNR{A[$1]=$2; next} {print $1, A[">" $1]}' file2 file1
ABC chr15:176578-187678[-]: ['CCTGCGT']
XYZ 
PQR chr3:14567-15866[+]: ['CCTYHGV','TLKJNWYT',TTGCDGT']

Do you need to get the colon removed as well?

2 Likes

Thanks, It worked. I really don't mind about the colon.

Hello Scrutinizer,

Thanks for excellent code :b:. could you please explain it.

Thanks,
R. Singh