Trying to write a script to rename files in directories to include directory name
Hi all,
I have a "main" directory containing many sub-directories that are all named like "FirstName_SecondName" (they are scientific names of animals with genus_species). In each of these directories there is a file called estscan_pep.fasta. I would like to copy each of the estscan_pep.fasta files to the "main" directory but replace the "estscan" part with the "FirstName_SecondName" part from the name of the folder in came from. I believe find and xargs are the tools for the job but I can't figure out the syntax. Could anyone give me some suggestions to get me started? Thanks! Kevin |
If the estscan_pep.fasta files are all at first level below the current directory, you can try something like this:
Code:
while read file; do echo cp -p $file ${file%/*}_pep.fasta; done < <(find . -type f -name estscan_pep.fasta) |
Sorry for the delay in replying. That's perfect. I had played with something like this but I had the syntax for "${file%/*}" all wrong.
Thanks! Kevin |
All times are GMT -5. The time now is 11:08 AM. |