3

I have a file lets say file1.txt

ENSG00000223116 AL157931.1  
ENSG00000233440 HMGA1P6 
ENSG00000207157 RNY3P4  
ENSG00000229483 LINC00362   
ENSG00000252952 RNU6-58P

I have another file say file2.txt

ENSG00000223117 0   0
ENSG00000223116 0   0
ENSG00000233440 1.71449394  50

I want to compare file1 with file2 for ENSG names and get the output such that if ENSG name in file 1 is present in file2 then output should be

ENSG00000223116 0   0 AL157931.1
ENSG00000233440 1.71449394  50 HMGA1P6

I can write a perl script for this but I just want to do this on command line. How can it be done?

Regards

  • Have you tried join? – muru Dec 10 '14 at 18:15
3

If you previous sort your files, you could do in a simple way:

$ join file2 file1
ENSG00000223116 0 0 AL157931.1
ENSG00000233440 1.71449394 50 HMGA1P6

To sort your files just do the following:

sort file1.txt > file1
sort file2.txt > file2
  • 4
    Or: join <(sort file2.txt) <(sort file1.txt) – muru Dec 10 '14 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.