I have 2 files. File1 is:
chr19 4124051 4124250 1
chrX 154458151 154458200 2
chr22 37019451 37019600 3
chr15 74995401 74995550 4
chr12 128823901 128824100 5
and File2 is:
chr19 4124051 4124250 1 CUP
chr15 74995401 74995550 4 CUP
chr12 128823901 128824100 5 CUP
chr12 122752651 122752950 8 CUP
chr13 113297001 113297350 9 CUP
and I would like to have a File3 like this:
chr19 4124051 4124250 1 CUP
chrX 154458151 154458200 2
chr22 37019451 37019600 3
chr15 74995401 74995550 4 CUP
chr12 128823901 128824100 5 CUP
I'd like to merge the two files according to column 4 of File1, and adding values of column 5 from File2 to the last column of File1 whenever there is a match.
I tired this:
awk 'FNR==NR{a[$4]=$5;next} {print $1,$2,$3,$4,a[$4]}' File2 File1 > file3
but it didn't work, it creates an extra row under each row.
And I tried join command as well:
join -1 4 -2 4 -o'1.1,1.2,1.3,1.4,2.5' File1 File2
and it creates an empty file.
Any suggestions?
sed
commands first to remove the\r
and then your other approaches should work as expected. By the way: please don't use Excel for bioinformatics analyses! Every time you do, you make a bioinformatician cry :P