Hi all,

I have done BLASTp searches on multiple genomes and pfam analysis. So now, I have numerous .pfam result files (text files) and I would like to extract only identical matches between two genomes. 

Instead of doing it manually, is there a bash command or else to **extract all identical words from text files**? 

I tried this:

    comm -12 file1.txt file2.txt > output.txt

But as I expected, I only have the common lines between the files while I need all common words...

If you have any ideas, please let me know!

Thank you in advance for your help. 

***EDIT: file examples***

**Here is an example of file1:** 

    #                                                               --- full sequence ---- --- best 1 domain ---- --- domain number estimation ----
    # target name        accession  query name           accession    E-value  score  bias   E-value  score  bias   exp reg clu  ov env dom rep inc description of target
    #------------------- ---------- -------------------- ---------- --------- ------ ----- --------- ------ -----   --- --- --- --- --- --- --- --- ---------------------
    WxL                  PF13731.7  Lactococcus_893      -            3.7e-07   30.4   7.2   5.2e-07   29.9   7.2   1.2   1   0   0   1   1   1   1 WxL domain surface cell wall-binding
    DUF916               PF06030.13 Lactococcus_894      -            7.3e-20   71.3   1.3   8.7e-20   71.0   1.3   1.0   1   0   0   1   1   1   1 Bacterial protein of unknown function (DUF916)
    DUF3324              PF11797.9  Lactococcus_895      -            3.2e-31  108.2   1.3   3.9e-31  107.9   1.3   1.1   1   0   0   1   1   1   1 Protein of unknown function C-terminal (DUF3324)
    APH                  PF01636.24 Lactococcus_896      -            3.2e-07   30.5   0.1   4.4e-07   30.0   0.1   1.1   1   0   0   1   1   1   1 Phosphotransferase enzyme family

**Here is an example of file 2:** 

    #                                                               --- full sequence ---- --- best 1 domain ---- --- domain number estimation ----
    # target name        accession  query name           accession    E-value  score  bias   E-value  score  bias   exp reg clu  ov env dom rep inc description of target
    #------------------- ---------- -------------------- ---------- --------- ------ ----- --------- ------ -----   --- --- --- --- --- --- --- --- ---------------------
    Beta-lactamase2      PF13354.7  Lactococcus_549      -            1.9e-33  115.8   0.0   2.8e-33  115.2   0.0   1.3   1   0   0   1   1   1   1 Beta-lactamase enzyme family
    S1                   PF00575.24 Lactococcus_550      -              0.014   15.8   0.7      0.47   10.9   0.7   2.3   1   1   0   1   1   1   0 S1 RNA binding domain
    DUF3324              PF11797.9 Lactococcus_551       -            3.4e-08   33.2   0.5   3.4e-08   33.2   0.5   1.9   2   0   0   2   2   2   1 Protein of unknown function C-terminal (DUF3324)


As in the two .txt files there is only the DUF3324 target name in common, I would want in an output file simply like this:

    DUF3324

I'm really thankful if you want to help me on this... 
The command you found is correct, you just need to use it correctly:

    comm -12 <(tail -n+4 file1.txt | cut -d ' ' -f 1| sort ) <(tail -n+4 file2.txt | cut -d ' ' -f 1| sort )

You don't need to do all of this in one line if you don't want to, but you do need to:

1. Trim the header lines out (`tail -n+4`)
2. Isolate just the first column, as defined by whitespace (`cut -d ' ' -f 1`)
3. `sort` the files in order for `comm` to work (if they aren't already sorted, which these aren't).