Renaming bulk directories and subfiles

Hi,

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.

Sample name file:

ABC_123 SRR191639
XYZ_IRT SRR191640
ABC_1LK SRR191641

output

The subdirectories and the child files should be renamed to

ABC_123->ABC_123.sra
XYZ_IRT->XYZ_IRT.sra
ABC_1LK->ABC_1LK.sra

Thanks,

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

Something like:

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

Remove the echo when you're sure it works.

Thanks for the reply.

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.

Hope I am clear

Could you share a few example lines of sample_info_file.txt?

Thanks Carlo. It worked..