text: user2040: I have a bed file like this:
  chr1    12227   12612   LOC102725121    0   +
  chr1    12721   13220   LOC102725121    0   +
  chr1    12227   12612   DDX11L1 0   +
  chr1    12721   13220   DDX11L1 0   +
  chr1    14829   14969   WASH7P  0   -
  chr1    15038   15795   WASH7P  0   -
  chr1    15947   16606   WASH7P  0   -
  chr1    16765   16857   WASH7P  0   -
  chr1    17055   17232   WASH7P  0   -
  chr1    17368   17605   WASH7P  0   -
  
  I am trying to convert into gtf file for downstream analysis. Gtf file should look like this:
  chr1   myIntrons   feature 3073253   3074322   .   +   .     gene_id "intron1"; transcript_id "intron1"
  chr1   myIntrons   feature 3075858   3079636   .   +   .     gene_id "intron2"; transcript_id "intron2"
  
  For the gene_id part in the 9th column in the double quotes I want my 4th column and in transcript_id I want combination of column1,column2,and column3 so that my output looks like this:
  Showing for the first line
  chr1    myIntrons   intron  12228   12612   .   +   .   gene_id "LOC102725121"; transcript_id "chr1:12227-12612"
  
  I am using this code but under double quotes it is not expanding $1 $2 etc
  awk -v OFS="\t" '{print $1,"myIntrons","intron", $2+1, $3, ".", $6, ".", "gene_id $4; transcript_id $1:$2-$3"}' file.bed| head
  
  
  user77: Instead of the "gene_id ..." bit, you want sprintf("gene_id \"%s\"; transcript_id \"%s:%s-%s\"", $4, $1, $2, $3).
  
original_text: 2040: <p>I have a bed file like this:</p>
  
  <pre><code>chr1    12227   12612   LOC102725121    0   +
  chr1    12721   13220   LOC102725121    0   +
  chr1    12227   12612   DDX11L1 0   +
  chr1    12721   13220   DDX11L1 0   +
  chr1    14829   14969   WASH7P  0   -
  chr1    15038   15795   WASH7P  0   -
  chr1    15947   16606   WASH7P  0   -
  chr1    16765   16857   WASH7P  0   -
  chr1    17055   17232   WASH7P  0   -
  chr1    17368   17605   WASH7P  0   -
  </code></pre>
  
  <p>I am trying to convert into gtf file for downstream analysis. Gtf file should look like this:</p>
  
  <pre><code>chr1   myIntrons   feature 3073253   3074322   .   +   .     gene_id "intron1"; transcript_id "intron1"
  chr1   myIntrons   feature 3075858   3079636   .   +   .     gene_id "intron2"; transcript_id "intron2"
  </code></pre>
  
  <p>For the gene_id part in the 9th column in the double quotes I want my 4th column and in transcript_id I want combination of column1,column2,and column3 so that my output looks like this:
  Showing for the first line</p>
  
  <pre><code>chr1    myIntrons   intron  12228   12612   .   +   .   gene_id "LOC102725121"; transcript_id "chr1:12227-12612"
  </code></pre>
  
  <p>I am using this code but under double quotes it is not expanding <code>$1 $2</code> etc</p>
  
  <pre><code>awk -v OFS="\t" '{print $1,"myIntrons","intron", $2+1, $3, ".", $6, ".", "gene_id $4; transcript_id $1:$2-$3"}' file.bed| head
  </code></pre>
   77: <p>Instead of the <code>"gene_id ..."</code> bit, you want <code>sprintf("gene_id \"%s\"; transcript_id \"%s:%s-%s\"", $4, $1, $2, $3)</code>.</p>
  