Here you have a script that I made yesterday for this exactly same purpose. It doesn't need any external package or third-party libraries. It is written in Perl. Usage is: ./extract_longest_from_trinity Trinity.fasta > Trinity.longest.fasta
Give it a try. Good luck!
(Apparently attachment was removed. I uploaded again without the file extension)