1

I would like to merge two files. I looked upon the previous questions and answers but none of them matches my desired output.
There are two csv files - file1.csv, file2.csv. file1.csv and file2.csv are not of same length. the program should merge both the files and printing everything from both file based on column 1
Input

file1.csv has 4 columns.

$ cat file1.csv
Contig_Spider_Gland_98_1_1,>Contig_Spider_Gland_98_1_1 [1169 - 963] (REVERSE SENSE),MQGHRRKLATPRQRAPRKERQRALLLRLQWRIGLQPCSRRNKSLDRKNIYWRYLVEYGSWKGRTHISDV,C# 
Contig_Spider_Gland_98_7_3,>Contig_Spider_Gland_98_17965_1 [90 - 278],MADVEKTSCCTETKECCKDETCCENGQGACHTGKEECKDTCHKKACGCKAGEDCKCSDGKCGC,CC#CC#CC#C#C#C#C#C#C#C#C#C# 

$ cat file2.csv
Contig_Spider_Gland_98_1_1, SignalP-4.1,     SIGNAL,  1,    22, 0.808,  YES
Contig_Spider_Gland_98_8_2, SignalP-4.1,    SIGNAL  1,  20, 0.877,  YES

Output

Contig_Spider_Gland_98_1_1,>Contig_Spider_Gland_98_1_1 [1169 - 963] (REVERSE SENSE),MQGHRRKLATPRQRAPRKERQRALLLRLQWRIGLQPCSRRNKSLDRKNIYWRYLVEYGSWKGRTHISDV,C#,Contig_Spider_Gland_98_1_1, SignalP-4.1,     SIGNAL,  1,   22, 0.808,  YES
Contig_Spider_Gland_98_7_3,>Contig_Spider_Gland_98_17965_1 [90 - 278],MADVEKTSCCTETKECCKDETCCENGQGACHTGKEECKDTCHKKACGCKAGEDCKCSDGKCGC,CC#CC#CC#C#C#C#C#C#C#C#C#C#,no match

Thank you for your help

  • 1
    ...printing everything from both files based on column 1 Your desired output contains only lines from file1.csv – don_crissti Oct 12 '15 at 9:58
  • what about line in file 2 missing from file 1 e.g. Contig_Spider_Gland_98_8_2 ? – Archemar Oct 12 '15 at 10:10
1

Is this what you want?

join -t, file1.csv file2.csv -a 1 -o auto -e 'no match'
Contig_Spider_Gland_98_1_1,>Contig_Spider_Gland_98_1_1 [1169 - 963] (REVERSE SENSE),MQGHRRKLATPRQRAPRKERQRALLLRLQWRIGLQPCSRRNKSLDRKNIYWRYLVEYGSWKGRTHISDV,C# , SignalP-4.1,     SIGNAL,  1,    22, 0.808,  YES
Contig_Spider_Gland_98_7_3,>Contig_Spider_Gland_98_17965_1 [90 - 278],MADVEKTSCCTETKECCKDETCCENGQGACHTGKEECKDTCHKKACGCKAGEDCKCSDGKCGC,CC#CC#CC#C#C#C#C#C#C#C#C#C# ,no match,no match,no match,no match,no match,no match

And if the lines form file2 need to be printed as well:

join -t, file1.csv file2.csv -a 1 -a2 -o auto -e 'no match'
Contig_Spider_Gland_98_1_1,>Contig_Spider_Gland_98_1_1 [1169 - 963] (REVERSE SENSE),MQGHRRKLATPRQRAPRKERQRALLLRLQWRIGLQPCSRRNKSLDRKNIYWRYLVEYGSWKGRTHISDV,C# , SignalP-4.1,     SIGNAL,  1,    22, 0.808,  YES
Contig_Spider_Gland_98_7_3,>Contig_Spider_Gland_98_17965_1 [90 - 278],MADVEKTSCCTETKECCKDETCCENGQGACHTGKEECKDTCHKKACGCKAGEDCKCSDGKCGC,CC#CC#CC#C#C#C#C#C#C#C#C#C# ,no match,no match,no match,no match,no match,no match
Contig_Spider_Gland_98_8_2,no match,no match,no match, SignalP-4.1,    SIGNAL  1,  20, 0.877,  YES,no match

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.