get gene lines from gtf file
Assuming none of the genes have duplicate entries across chromosomes (or strand or other biologically implausible things) in R one can:

library(rtracklayer)
library(GenomicRanges)
gtf = import.gff("file.gtf")
grl = split(gtf, gtf$gene_id)  # This produces a GRangesList
grl = endoapply(grl, function(x) {
    foo = x[1]
    foo$type = 'gene'
    start(foo) = min(start(x))
    end(foo) = max(end(x))
    return(c(foo, x))
    })
gr = unlist(gr)


You can then either write gr out to a file (either with export() or just printing the rows).