text: user1247: I have two file that have overlapping regions. One file has chromosomes, position, CNV data and samples.Other file has chromosomes, positions and ensemble ids of genes.
  Here is some lines of two files.
  contig  start   end     type  bi-allelic  S1  S2  S3
  chr1    12048   177033    DUP FALSE   -1  22  24
  chr1    12048   89237     DUP FALSE   12  10  -1
  chr1    2985712 3355300   DEL   TRUE  2   2   2
  
  Second file is like this
  chr1    901877  911245  gene_id "ENSG00000187583.6"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  chr1    22013   41670 gene_id "ENSG00000160075.10"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  chr1    2985732 3355185 gene_id "ENSG00000142611.12"
  
  I want output like this.
  chr1    22013   41670 gene_id "ENSG00000160075.10"  DUP FALSE   12  10  -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  chr1    2985732 3355185 gene_id "ENSG00000142611.12" DEL   TRUE  2   2   2 
  
  Is there any way to do this?
  
  user77: You can use bedtools intersect and cut the results:
  $ cat file1.bed
  chr1    12048   177033  DUP FALSE   -1  22  24
  chr1    12048   89237   DUP FALSE   12  10  -1
  chr1    2985712 3355300 DEL TRUE    2   2   2
  
  $ cat file2.gtf
  chr1    22013   41670   gene_id "ENSG00000160075.10"
  chr1    22013   41670   gene_id "ENSG00000160075.10"
  chr1    2985732 3355185 gene_id "ENSG00000142611.12"
  
  $ bedtools intersect -a file2.gtf -b file1.bed -wb | cut -f 1-4,8-11
  chr1    22013   41670   gene_id "ENSG00000160075.10"    DUP FALSE   12  10
  chr1    22013   41670   gene_id "ENSG00000160075.10"    DUP FALSE   -1  22
  chr1    2985732 3355185 gene_id "ENSG00000142611.12"    DEL TRUE    2   2
  
  
original_text: 1247: <p>I have two file that have overlapping regions. One file has chromosomes, position, CNV data and samples.Other file has chromosomes, positions and ensemble ids of genes.</p>
  
  <p>Here is some lines of two files.</p>
  
  <pre><code>contig  start   end     type  bi-allelic  S1  S2  S3
  chr1    12048   177033    DUP FALSE   -1  22  24
  chr1    12048   89237     DUP FALSE   12  10  -1
  chr1    2985712 3355300   DEL   TRUE  2   2   2
  </code></pre>
  
  <p>Second file is like this</p>
  
  <pre><code>chr1    901877  911245  gene_id "ENSG00000187583.6"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  chr1    22013   41670 gene_id "ENSG00000160075.10"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  chr1    2985732 3355185 gene_id "ENSG00000142611.12"
  </code></pre>
  
  <p>I want output like this.</p>
  
  <pre><code>chr1    22013   41670 gene_id "ENSG00000160075.10"  DUP FALSE   12  10  -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  chr1    2985732 3355185 gene_id "ENSG00000142611.12" DEL   TRUE  2   2   2 
  </code></pre>
  
  <p>Is there any way to do this?</p>
   77: <p>You can use <code>bedtools intersect</code> and cut the results:</p>
  
  <pre><code>$ cat file1.bed
  chr1    12048   177033  DUP FALSE   -1  22  24
  chr1    12048   89237   DUP FALSE   12  10  -1
  chr1    2985712 3355300 DEL TRUE    2   2   2
  
  $ cat file2.gtf
  chr1    22013   41670   gene_id "ENSG00000160075.10"
  chr1    22013   41670   gene_id "ENSG00000160075.10"
  chr1    2985732 3355185 gene_id "ENSG00000142611.12"
  
  $ bedtools intersect -a file2.gtf -b file1.bed -wb | cut -f 1-4,8-11
  chr1    22013   41670   gene_id "ENSG00000160075.10"    DUP FALSE   12  10
  chr1    22013   41670   gene_id "ENSG00000160075.10"    DUP FALSE   -1  22
  chr1    2985732 3355185 gene_id "ENSG00000142611.12"    DEL TRUE    2   2
  </code></pre>
  