I have an input that is in a multi-fasta format. Essentially:
>header1
AAAAAATTTTCCCCGGGG
AAAATGTGTGTCTCTCTC
ATAGGATGAGT
>header2
GGGGTGTGTGATGTAGTA
AAAATGTGTGTCTCTCTC
ATAGGATGAGT
....
>header720
GGGGTGCTCGCTCTGTGA
AAAATGAGTCATCATTGT
ATAGGATGAGT
I am interested in recovering entry #28 in this format:
>header28
GGGGTGCTCGCTCTGTGA
AAAATGAGTCATCATTGT
ATAGGATGAGT
My initial attempt was to use sed. However,
sed -n '/header28/,/>/p'
('get everything from the line matching the pattern to the next symbol >') leads to:
>header28
GGGGTGCTCGCTCTGTGA
AAAATGAGTCATCATTGT
ATAGGATGAGT
>header29
Meanwhile, sed -n '/header28/,/[^>]*/p'
('get everything from the line matching the pattern to, but not including, the symbol >') results in a shorter sequence than I need because it gets stuck on the newlines as follows:
>header28
GGGGTGCTCGCTCTGTGA
In addition, none of these options deal with the possibility that the entry is the last in the list (and therefore not followed by another >). This is unlikely, and I could live with it, but code which could deal with this too would be great.
Help would be much appreciated! Open to other options than sed, but I thought I would aim for something simple.