I have two tab-separated with header text file.
File1 has 11 columns
Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 Col1
1 NH1 NH1 Unknown 149578 B2 202410200023_R02C02
2 NH2 NH2 Unknown 149578 A4 202410200023_R04C01
10 NH10 NH10 Unknown 149578 A1 202410200023_R01C01
11 BU51 BU51 Unknown 149578 B3 202410200023_R03C02
12 BU52 BU52 Unknown 149578 A6 202410200023_R06C01
file2 has 4, 5 or more columns.
Col1 Col2 Col3 Col4 Col5
BU51 149578 BU51 Unknown 1
BU52 149578 BU52 Unknown 1
NH1 149578 NH1 Unknown 1
NH2 149578 NH2 Unknown 1
I try to make a output with column 2 to 4 from file 1 and column 4 and 5 from file2. But the col2 or col3 from file1 need to match with col1 or col2 from file2. The columns of output may have new locations. Such as column2 from file1 may be located at column1 in output
I try to find the answer from How to compare and merge multiple files?
I am not sure why the line foreach my $key (keys %ref){ push( @{$ref{$key} }, $current{key}}
can not work well.