One liner to remove the description information from a fasta file and just keep the identifier $ perl -p -i -e 's/>(.+?) .+/>$1/g' sample1.fa #clean#header#fasta
perl -ne 'if(/^>(\S+)/){$c=grep{/^$1$/}qw(id1 id2)}print if $c' fasta.file
If you have a large number of sequences that you want to extract, then you most likely have the sequence identifiers in a separate file. Assuming that you have one...