0

I have a the following file as input:

chr1    HAVANA  exon    11869   12227   .   +   .   gene_id "ENSG00000223972.5_2"; transcript_id "ENST00000456328.2_1"; gene_type "transcribed_unprocessed_pseudogene"; gene_name "DDX11L1"; transcript_type "processed_transcript"; transcript_name "DDX11L1-002"; exon_number 1; exon_id "ENSE00002234944.1_1"; level 2; transcript_support_level 1; tag "basic"; havana_gene "OTTHUMG00000000961.2_2"; havana_transcript "OTTHUMT00000362751.1_1"; remap_original_location "chr1:+:11869-12227"; remap_status "full_contig";
chr1    HAVANA  exon    12010   12057   .   +   .   gene_id "ENSG00000223972.5_2"; transcript_id "ENST00000450305.2_1"; gene_type "transcribed_unprocessed_pseudogene"; gene_name "DDX11L1"; transcript_type "transcribed_unprocessed_pseudogene"; transcript_name "DDX11L1-001"; exon_number 1; exon_id "ENSE00001948541.1_1"; level 2; transcript_support_level "NA"; ont "PGO:0000005"; ont "PGO:0000019"; tag "basic"; havana_gene "OTTHUMG00000000961.2_2"; havana_transcript "OTTHUMT00000002844.2_1"; remap_original_location "chr1:+:12010-12057"; remap_status "full_contig";

This is a 9 column file separated by tabs.

I want to print column 1,4,5,7 and from column 9 the gene_name part such that the output should be

chr1    11869   12227   +   DDX11L1
chr1    12010   12057   +   DDX11L1

I thought of using awk and sed combination but I am unable to get what I want

awk -v OFS="\t" -F "\t" '{print $1,$4,$5,$7,$9}' | sed 's/gene_name\s"\(.+\)";\stran*/\1/'

Any help would be appreciated.

Thanks

3 Answers 3

3

If you have GNU awk, you can use gensub to do the replacement using a suitable regex e.g. assuming everything from gene_id is a single tab-delimited field 9:

gawk -F '\t' '{$9 = gensub(/.*gene_name "([^"]*)".*/,"\\1","1",$9); print $1,$4,$5,$7,$9}' input
chr1 11869 12227 + DDX11L1
chr1 12010 12057 + DDX11L1
2

Use awk with multiple separators.

 awk -F"[\" \t]" '{print $1,$11,$14,$20,$40}' infile.txt 
0
0

awk uses a space as a delimiter.

Try this:

$ awk '{print $1, $4, $5, $7, substr($16, 2, 7) }' file
chr1 11869 12227 + DDX11L1
chr1 12010 12057 + DDX11L1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .