#!/usr/bin/env sh
gene_id_1="${1}"
gene_id_2="${2}"
fasta_file="${3}"
output_file="${4}"
echo "" > "${output_file}"
for gene_id in ${gene_id_1} ${gene_id_2}; do
    awk -v gene_id="${gene_id}" '
        BEGIN {
            on_gene=0
            visited=0
        }
        /^[^>]/ && on_gene == 1 {
            
            print $0
        }
        /^>/ {
            if (visited == 1) {
                    exit
            }
            gene = $4
            gsub("gene:", "", gene)
            if (gene == gene_id) {
                on_gene=1
                print $0
                visited=1
            } else {
                on_gene=0
            }
        }
        ' "${fasta_file}" >> "${output_file}"
done
