I have a folder with a couple thousand files and I want to move them into subfolders according to a string in the filename. The files all have a structure like
something-run1_001.txt
something-run22_1243.txt
So I tried the following script in order to move all files with “run1” in it into a subfolder r1 and all “run22” files in a subfolder r22 (and so on) but it does no work that way and I get a message “File X is the same as file X”.
#!bin/bash
for i in {1..39}
do
foldername=r$i
#echo "$foldername"
mkdir $foldername
find . -type f -name "*run$i_*" | xargs -i mv {} $foldername/
done
How to solve this?
1 Answer