I have a csv file as shown below,
xop_thy 80 avr_njk 50 str_nyu 60
avr_irt 70 str_nhj 60 avr_ngt 50
str_tgt 80 xop_nmg 50 xop_nth 40
cyv_gty 40 cop_thl 40 vir_tyk 80
vir_plo 20 vir_thk 40 ijk_yuc 70
cop_thy 70 ijk_yuc 80 irt_hgt 80
I need to align/sort the csv file based on the order mentioned in another file (keyword file) as shown below,
xop
avr
str
cyv
vir
cop
ijk
irt
The desired output is shown below,
xop_thy 80 xop_nmg 50 xop_nth 40
avr_irt 70 avr_njk 50 avr_ngt 50
str_tgt 80 str_nhj 60 str_nyu 60
cyv_gty 40
vir_plo 20 vir_thk 40 vir_tyk 80
cop_thy 70 cop_thl 40
ijk_yuc 80 ijk_yuc 70
irt_hgt 80
The major condition is the column to be arranged pair wise (while rearrangement the string column should take the concerned value column adjacent to it together) like wise the pairs of columns to be rearranged based on the keywords. Another problem the keyword is the starting letters of each column, the keyword file has only starting strings of the columns strings. each column pairs are having common keyword but after the underscore symbol it vary. Therefore, I do not know how to make code for it. If it number or alphabet based sorting I can use
function. But here i could not use it due to the complexity of condition. I am not sure, Is it possible to do the same. if it possible please help me.
Thanks in advance.