I have some files whose name looks like this:
XXXXX_S1_X_XX_X.txt
XXXXX_S2_X_XX_X.txt
XXXXX_S3_X_XX_XXX.txt
S4_X_XX_X.txt
XXXXX_S5_XX_X.txt
...
I created a list of folders named: S1
, S2
, S3
, .... I would like to move the file XXXXX_S1_X_XX_X.txt
in the folder S1
, the file XXXXX_S2_X_XX_X.txt
in the folder S2
and so on. I wrote this simple loop but I don't know how to copy/move files according to the pattern matching S* in the corresponding folder:
for i in My_list_of_folders.txt
do
dir=${i%.txt}
mkdir "$dir"
cp "$i" "$dir"
done