I have an array a that the following lines
rs6605071 chr1:962943 C ENSG00000188976 ENST00000487214
rs6605071 chr1:962943 C ENSG00000187961 ENST00000622660
rs6605071 chr1:962943 C 84069 NM_001160184.1
rs6605071 chr1:962943 C 339451 NC_006462594.2
rs6605071 chr1:962943 C 339451 XR_001737138.1
rs6605071 chr1:962943 C 339451 XM_006710600.3
and another ordered array b that has the following lines:
NC
NG
NM
NP
NR
XM
XP
XR
WP
I would like to order the lines in array a to match the order of array b on column 5 to obtain to desired output:
rs6605071 chr1:962943 C 339451 NC_006462594.2
rs6605071 chr1:962943 C 84069 NM_001160184.1
rs6605071 chr1:962943 C 339451 XM_006710600.3
rs6605071 chr1:962943 C 339451 XR_001737138.1
rs6605071 chr1:962943 C ENSG00000188976 ENST00000487214
rs6605071 chr1:962943 C ENSG00000187961 ENST00000622660
I tried to do the following command by splitting on column 5 but it is printing blank lines:
awk -F '\t' -v OFS='\t' 'FNR==NR{split(a[$5],t,"_"); t[1]=$0;next}
{print a[$1]}' <(printf '%s\n' "${a[@]}") <(printf '%s\n' "${b[@]}")
Could you please tell me why my command is not working ? Would a partial match by regex work ?
EDIT 1: changing array a to include lines that can have multiple codes from array b
rs6605071 chr1:962943 C ENSG00000188976 ENST00000487214
rs6605071 chr1:962943 C ENSG00000187961 ENST00000622660
rs6605071 chr1:962943 C 84069 NM_001160184.1
rs6605071 chr1:962943 C 339451 NC_006462594.2
rs6605071 chr1:962943 C ENSG00000135234 ENST00000624144
rs6605071 chr1:962943 C 339451 XR_001737138.1
rs6605071 chr1:962943 C 334324 NC_006462632.2
rs6605071 chr1:962943 C 84333 NM_004353462.1
rs6605071 chr1:962943 C 339451 XM_006710600.3
Expected output:
rs6605071 chr1:962943 C 334324 NC_006462632.2
rs6605071 chr1:962943 C 339451 NC_006462594.2
rs6605071 chr1:962943 C 84069 NM_001160184.1
rs6605071 chr1:962943 C 84333 NM_004353462.1
rs6605071 chr1:962943 C 339451 XM_006710600.3
rs6605071 chr1:962943 C 339451 XR_001737138.1
rs6605071 chr1:962943 C ENSG00000188976 ENST00000487214
rs6605071 chr1:962943 C ENSG00000187961 ENST00000622660
rs6605071 chr1:962943 C ENSG00000135234 ENST00000624144
EDIT 2: Since the answer provided by RavinderSingh13 below did not fully answer my question, I will re-ask the question on how to perform such task with AWK.
Thanks in advance.
NC_lines in arraya?XR_001737138.1and it would split them on_...a