This is my bed file for all the exon coordinates ..small subset so i want to take out all the exons that of a given gene let say i have gene in chr 1 which starts from `chr1	11868	12227` so i want to parse out all the exons that comes in between `11868	12227`

this is my small subset 

    cat exon.bed | head -10
    chr1	11868	12227	+	exon
    chr1	11871	12227	+	exon
    chr1	11873	12227	+	exon
    chr1	12009	12057	+	exon
    chr1	12178	12227	+	exon
    chr1	12594	12721	+	exon
    chr1	12612	12697	+	exon
    chr1	12612	12721	+	exon
    chr1	12612	12721	+	exon
    chr1	12974	13052	+	exon

How do i parse out , i use mostly R and bit of shell script but I m not sure if i can use R , may a few lines of perl or shell script can help me solve my problem.

Any help or suggestion would be highly appreciated 
Via BEDOPS `bedops -n` and Unix I/O streams:

    $ echo -e "chr1\t11868\t12227" | bedops -n 1 exon.bed - > answer.bed

Or, if you have your genes in a BED file called `genes.bed`:

    $ bedops -n 1 exon.bed genes.bed > answer.bed

If you have your genes in some other format, like GFF or GTF, you can use `gff2bed` or `gtf2bed`, e.g.:

    $ bedops -n 1 exon.bed <(gff2bed < genes.gff) > answer.bed

Or:

    $ bedops -n 1 exon.bed <(gtf2bed < genes.gtf) > answer.bed

The file `answer.bed` will contain exons that do not overlap a gene annotation.