I want to create new directories and simultaneously move the files in the corresponding directories according to the first digit in the file name which is attached with the c_g_se segment. In this case there will be four directories like New_dir1, New_dir2 .. so on. Here c_g_se1_gb.ph, c_g_se1_gb.ph_pl_s.t and c_g_se1_gb.ph_pl_tr.t will be the content of New_dir1.
This is what I did for testing but its not creating multiple directories. If it work then I will add may be two more for loops for .ph_pl_s.t and .ph_pl_tr.t files
#!/bin/bash
if [ "$1" == "-h" ]; then
echo "Usage: `basename $0` [Please Enter the starting_file_digit and ending file digit: run as find_move.sh 1 3175]"
exit 0
fi
printf "\n"
echo Finding and moving *.ph Files from c_g_se"$1"_gb.ph to c_g_se"$2"_gb.ph
for (( c="$1"; c<="$2"; c++ ))
do
find -name '*.ph' -exec sh -c 'mkdir -p New_dir"$c" && cp "$@" New_dir"$c"' _ {} +
printf "\n"
done
EDIT: OK, let's be constructive. WHAT "is not working", and how? Please post data to work upon (execution logs, error messages). For me, this was the output:
Of course no directory was created nor was a file moved - the commands were echo ed to the screen for control purposes. Redirecting to find_n_move.sh and the running that is one option. One other would be to read my post#6 to its entirety and remove the echo es as proposed.
To your second question: What do you expect people to do with the little info you give? May I repeat myself (post#8): WHAT "is not working", and how? Please post data to work upon (execution logs, error messages.
Aside: your construct cp "$@" New_dir"$c"' _ {} seems a bit weird...