I have a directory with 100 subdirectories and each of these subdirectories has 1 file. Now I have to rename all these.
The structure is "files directory has 100 SRR191639-SRR191718 subfolders and in each there is a file with the same name a subdirectory followed by .sra extension (SRR191639.sra)
example files->SRR191639->SRR191639.sra
Like this I have 100 files
I have a another file which has the sample names corresponding to these SRR numbers. Now I want to rename the subdirectories and the file in those directories with the sample names.
If i understood you properly you actualy just want to rename the folders.
They are named like ABC_123 and should be named ABC_123.sra.
cd /path/to/folders
for each in $(ls);do mv $each $each.sra;done
Hope this helps
EDIT:
cd /path/to/folders
for each in $(ls);do
for eachfile in $(cd $each;ls);do mv $each/$eachfile $each/$eachfile.sra;done # Renames the files in folder $each
mv $each $each.sra # Renames the folder
done
cd files
for i in SRR*
do
newname=$(awk -vsrch=$i '$0 ~ srch {print $1}' samples.txt)
if [ "x"$newname != "x" ]
then
echo mv $i/$i.sra $i/$newname.sra
echo mv $i $newname
fi
done
Nope I want to change the directory name and also the filename in the directory to the names I have in sample_info_file.txt
My sample_info_file.txt has two columns one with the directories name and other with its corresponding sample name. So I want the program to read my sample_info file and based on its corresponding directory name change both the directory and the its child file name to the sample name.