I have 2 tab separated file like these small examples:
example1:
RBM3 1517 993 -0.611355
RBM4 142 142 0
PRKAG1 146 73 -1
MORF4L2 1766 715 -1.30447
example2:
PCNP 370 139 -1.41244
RBM3 60 60 0
COTL1 338 252 -0.4236
PRKAG1 276 225 -0.294743
I want to get the common rows based on column 1 (in both files) and make a new file with 7 columns in which the 1st column is the 1st column in the original files and columns 2, 3 and 4 are from the 1st file and columns 5, 6 and 7 are from 2nd file (columns 2, 3 and 4). here is the expected output:
expected output:
RBM3 1517 993 -0.611355 60 60 0
PRKAG1 146 73 -1 276 225 -0.294743
I am trying to do that in AWK using the following code:
awk -v OFS="\t" 'NR==FNR {n[$2]=$1;next} ($2 in n) {print $1, $2, $3, $4, n[$2], n[$3], n[$4]}' file1 file2 > results.txt
but the results is not correct. do you have any idea how to fix it?