Comparing and merging two text files

Hey everybody,

I am new here and already a question to ask, I just recently started some bioinformatic work for my PhD so I am slowly learning

Anyway, here is my problem, I have two text files, one contains the complete data file with 43000 genes and their read counts for all my samples (actually 13 columns in total):

Ant-TAContig10	2025	1276	731	308	237	63	296	
Ant-TAContig100	5340	1711	7322	1088	5018	757	2788	
Ant-TAContig1000	1101	428	650	164	358	67	301	
Ant-TAContig10000	3585	1882	2621	532	838	216	

And the other text file is a list of the 21000 genes which have high expression value that I want to extract

Ant-TAContig10
Ant-TAContig100
Ant-TAContig1000
Ant-TAContig10000
Ant-TAContig10003
Ant-TAContig10005
Ant-TAContig10006

Okay so all I want to do is extract the genes in file 2 from the file 1 so I get expression value of only these 21000 genes

I sorted the files and tried join

join file1 file2 > out.txt

But the outfile is empty

I tried comm and diff but nothing seems to work

Any ideas why it does not work and hints for me please?

Thanks again everybody, have a nice sunday

ant55,
You will need to read the rules on how to post and use coding tags.

Your initial solution works on Solaris 10 but not sure on the version of Unix you are using.

join file1 file2 > out1                                                        
cat out1
Ant-TAContig10 2025 1276 731 308 237 63 296 
Ant-TAContig100 5340 1711 7322 1088 5018 757 2788 
Ant-TAContig1000 1101 428 650 164 358 67 301 
Ant-TAContig10000 3585 1882 2621 532 838 216

You can also try these solutions:

join -t " " -1 1 -2 1 file1 file2 
Ant-TAContig10 2025 1276 731 308 237 63 296 
Ant-TAContig100 5340 1711 7322 1088 5018 757 2788 
Ant-TAContig1000 1101 428 650 164 358 67 301 
Ant-TAContig10000 3585 1882 2621 532 838 216
 
nawk 'FNR==NR{arr[$1]=$0;next} {if (arr[$1] != "")  print arr[$1]}' file1 file2
Ant-TAContig10 2025 1276 731 308 237 63 296 
Ant-TAContig100 5340 1711 7322 1088 5018 757 2788 
Ant-TAContig1000 1101 428 650 164 358 67 301 
Ant-TAContig10000 3585 1882 2621 532 838 216

Note that your solution and the other 2 above will not tell you if a record is in file2 but not file1 which is present in your sample files.