Hi Monks, I'd just like to thank all of you who are so willing to help those in need; it's really great to see such a helpful community. My current issue is dealing with two space delimited files. The first file has column 1 as the sample ID's, then columns 2 - n as the observations. The second file has column 1 as the sample ID's, column 2 as the mother ID's, column 3 as the father ID's, column 4 as the gender, and column 5 as the trait. I would like a perl script that reads the first column of both files, and for the cells that match, copy over columns 2 - 5 from file 2 into the same position in file 1.
File 1 3936 C C C C A C ..... File 2 3936 3451 3607 1 1 3937 3451 3607 1 1 3938 3451 3607 1 1 3939 3451 3607 1 1 3940 3451 3607 2 1 3941 3451 3607 2 1 3942 3451 3607 2 1 3943 3451 3607 2 1 3944 3451 3607 2 1 Final File 3936 3451 3607 1 1 C C C C A C .....
I have tried the method of unix with the awk command for each column, but it did not work the way I wanted nor was it efficient:
Thank you for any helpawk 'NR==FNR{A[$1]=$1}A[$3]{sub($3,A[$3]);print}' file2 file1 > new fi +le
In reply to Two files; if cells match then copy over other columns by Renyulb28
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |