You're making another assumption here: that the FASTA entries are single-line. If you have multi-line FASTA, this script won't work. Plus, this script cannot handle empty lines. It would also look a lot cleaner with extended regex sed:
sed -Ee 's/^.*(.{100})$/\1/' file.fasta
Use
bioawkorsubstrinawkwith pre-calcuated sequence lengths (you can uselength()for that). Read: https://www.gnu.org/software/gawk/manual/html_node/String-Functions.htmlThanks RamRS. I think this command works when I know the length of the introns. But I have different lengths and I want the last 100 bases from each sequence.
You could use
length($seq)in biooawk to calculate length on the fly. I don't see why you need to know length before you start the entire operation. It just needs to be calculated before thesubstrstep.Thanks everyone. The
sed -Ee 's/^.*(.{100})$/\1/' file.fastaworked great. Appreciate it.Please accept answers that worked for you. You can accept more than one answer if they all work.