Hi all,

I have multiple files that have the same (long) title format:
Lactococcus_lactis_subsp_cremoris_strain_number_file.gbk_fasta.fasta_proteins.fasta_results

I want to delete everything after ".fasta" so it would be something like:
Lactococcus_lactis_subsp_cremoris_strain_number_file.gbk_fasta.fasta

I tried to make a small bash script in order to do that quickly but when I run it, nothing is changing.
Here is my script:

    #!/bin/bash
    
    for file in /home/Documents/Folder;
    do
    cut -d_ -f1,2,3,4,5,6,7,8 <<< "$f";
    done

There is obviously something wrong with it but I can't find where ... 

If you have any ideas/suggestions for improvements, please, let me know.

Thank you for your help!




`cut` operates on file contents, not file names - not unless used much differently. Plus, your loop variable is called `$file` while your loop uses something called `$f`.

You should go with sed. It could be done with bash parameter expansion too, but sed is easier.

In your case, you'd need something like

    echo "mv ${file} $(echo $file | sed 's/.fasta.*/.fasta/')" #untested - the first "." in the sed expression might need escaping

If the above `echo`s `mv` commands as expected, remove the echo and the double quotes surrounding the `mv` command to execute the command.