I have a folder with 4000 (*3) files like
gr_q4_gb-1.anc
gr_q4_gb-1.anc_cdr_st.txt
gr_q4_gb-1.anc_cdr_tr.txt
gr_q4_gb-2.anc
gr_q4_gb-2.anc_cdr_st.txt
gr_q4_gb-2.anc_cdr_tr.txt
gr_q4_gb-3.anc
gr_q4_gb-3.anc_cdr_st.txt
gr_q4_gb-3.anc_cdr_tr.txt
.
.
gr_q4_gb-4000.anc
gr_q4_gb-4000.anc_cdr_st.txt
gr_q4_gb-4000.anc_cdr_tr.txt
I want to split this into 150 subfolders. The folder containg 3 types of related files, for example gr_q4_gb-2.anc, gr_q4_gb-2.anc_cdr_st.txt and gr_q4_gb-2.anc_cdr_tr.txt are related and shoud go into a same folder. Roughly every subfolder would have 27 (*3) files.
RudiC
September 21, 2017, 3:42am
2
Any attempts / ideas / thoughts from your side?
Do all those file names follow the same structure, i.e. they all have gr_q4_gb
and .anc
as substrings? Are the number in strict sequence?
What should the subdirectories' names look like?
rudic:
Any attempts / ideas / thoughts from your side?
Do all those file names follow the same structure, i.e. they all have gr_q4_gb
and .anc
as substrings? Are the number in strict sequence?
What should the subdirectories' names look like?
I did this after separating the three types of files in three folders
i=0;
for f in *;
do
d=dir_$(printf %03d $((i/150+1)));
mkdir -p $d;
mv "$f" $d;
let i++;
done
Then merged the folders together
Yes, the files have same structure and gr_q4_gb
and .anc
used as substrings and the mumber sre in strict sequence.
the subdirectories names look like MLtr_1, MLtr_2,.... MLtr_150
RudiC
September 21, 2017, 4:00am
4
And where and how does that fail?
That worked, but I don't think it i good solution.
RudiC
September 21, 2017, 4:15am
6
Not sure if this is any better:
for i in {1..27}; do echo mkdir dir_$i; done
for FN in *.anc; do TMP=${FN##*-}; echo mv $FN* dir_$((${TMP%.*}/150+1))/; done
Remove the echo
if you like what you see.
rudic:
Not sure if this is any better:
for i in {1..27}; do echo mkdir dir_$i; done
for FN in *.anc; do TMP=${FN##*-}; echo mv $FN* dir_$((${TMP%.*}/150+1))/; done
Remove the echo
if you like what you see.
it gives
bash: */150+1: syntax error: operand expected (error token is "*/150+1")