I have a lot of FASTA files that I recently scaffolded with RagTag. The output of RagTag includes a directory for each sample and the corresponding FASTA file written as "ragtag.scaffold.fasta"
I would like to go through each file and rename it like so:
Original Path with File name:
directoryName_ID/ragtag.scaffold.fasta
Changed File name:
directoryName_ID/ID_ragtag.scaffold.fasta
As you can see, the directory name includes the ID number I would like to use to rename the fasta file with (along with an underscore to space it out). Is there a way to loop through all of the directories, using that last number after the "_" in the directory name and to use that to rename my fasta file?
Here is what I have tried so far:
for filename in ./directory*/ragtag.scaffold.fasta; do
mv filename ${./directory%*_*}_ragtag.scaffold.fasta;
done
It doesn't work at all but I know I need to use mv to rename the filename. However, when it comes to referencing the directory name the file is located in I get lost. I also have a .txt file that contains a list of IDs if that might be easier to reference. I'm still kinda new to the command line so if anyone could help that would be greatly appreciated!