I have a dataset that looks something like this:
chr1    StringTie   exon    197757319   197757401   1000    +   .   gene_id "MSTRG.10429"; transcript_id "ENST00000440885.1"; exon_number "1"; gene_name "RP11-448G4.4"; ref_gene_id "ENSG00000224901.1";
chr1    StringTie   exon    197761802   197761965   1000    +   .   gene_id "MSTRG.10429"; transcript_id "ENST00000440885.1"; exon_number "2"; gene_name "RP11-448G4.4"; ref_gene_id "ENSG00000224901.1";
chr9    StringTie   exon    63396911    63397070    1000    -   .   gene_id "MSTRG.145111"; transcript_id "MSTRG.145111.1"; exon_number "1";
chr9    StringTie   exon    63397111    63397185    1000    -   .   gene_id "MSTRG.145111"; transcript_id "MSTRG.145111.1"; exon_number "2";
chr21   StringTie   exon    44884690    44884759    1000    +   .   gene_id "MSTRG.87407"; transcript_id "MSTRG.87407.1"; exon_number "1";
chr22   HAVANA  exon    19667023    19667199    .   +   .   gene_id "ENSG00000225007.1"; transcript_id "ENST00000452326.1"; exon_number "1"; gene_name "AC000067.1";
chr22   HAVANA  exon    19667446    19667555    .   +   .   gene_id "ENSG00000225007.1"; transcript_id "ENST00000452326.1"; exon_number "2"; gene_name "AC000067.1";
I want to isolate the gene_ids. Therefore, the desired output is:
MSTRG.10429
MSTRG.10429
MSTRG.145111
MSTRG.145111
MSTRG.87407
ENSG00000225007.1
ENSG00000225007.1
I've tried the following:
grep -E -o "gene_id.{0,20}" gtf_om_ENSGids_te_vinden.gtf > alle_gene_ids.txt
With this I can grep the 20 characters after "gene_id" and I wanted to later remove the other characters which do not belong to the answer such as parts of the word "transcript". However, a problem is that the ref_gene_ids also get copied, which does not belong to the desired output. I tried to solve this by adding the -w flag, but this is also wrong for some reason. Can anyone help?
Thanks!
 
     
    