To edit the header of the fasta file as you specify, use this Perl one-liner:
echo '>sp.A9L976 PSBA_LEMMI Photosystem II protein D1 organism=Lemna minor taxid=4472 gene=psbA' | perl -lpe 's{^(>\S+\s+)\S+\s+}{$1}'
Prints:
>sp.A9L976 Photosystem II protein D1 organism=Lemna minor taxid=4472 gene=psbA
Note that it changes the fasta headers only, keeping the sequence intact even in the relatively rare cases when the sequence has whitespace. This is important in bioinformatics applications:
echo ">sp.A9L976 PSBA_LEMMI Photosystem II protein D1 organism=Lemna minor taxid=4472 gene=psbA\nACTG ACTG ACTG" | perl -pe 's{^(>\S+\s+)\S+\s+}{$1}'
Prints:
>sp.A9L976 Photosystem II protein D1 organism=Lemna minor taxid=4472 gene=psbA
ACTG ACTG ACTG
To edit the file in place:
perl -i.bak -lpe 's{^(>\S+\s+)\S+\s+}{$1}' in_file.fasta
The Perl one-liner uses these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-p : Loop over the input one line at a time, assigning it to $_ by default. Add print $_ after each loop iteration.
-l : Strip the input line separator ("\n" on *NIX by default) before executing the code in-line, and append it when printing.
-i.bak : Edit input files in-place (overwrite the input file). Before overwriting, save a backup copy of the original file by appending to its name the extension .bak.
Here,
^ : beginning of the line.
> : literal "greater than" character, which marks the beginning of the header in fasta format specifications.
\S+ : 1 or more non-whitespace characters.
\s+ : 1 or more whitespace characters.
$1 : 1st captured pattern. Capture occurs using parentheses: (...).
SEE ALSO:
perldoc perlrun: how to execute the Perl interpreter: command line switches
perldoc perlre: Perl regular expressions (regexes)
awk '{$2 = ""} 1' file