我有数千个或超过数千个文件,例如
A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=xxx23,celltracefile_DUL1_3.bin.gz
A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=ggg13,celltracefile_DUL1_3.bin.gz
A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=aaa56,celltracefile_DUL1_3.bin.gz
A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=slsf86,celltracefile_DUL1_3.bin.gz
A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=ccc57,celltracefile_DUL1_3.bin.gz
我正在尝试cut
- sort
- uniq
xxx23
、ggg13
、aaa56
、slsf86
字符,有数千个。计算其中有多少个,将其作为 800 个 uniq xxx23
、ggg13
、aaa56
、的一堆转移到子文件夹slsf86
中,将它们从源转移到其中 800 个 uniq 的多个文件夹中。
我的想法是,将列表放入数组并调用每个子文件夹的数组值,我怎样才能使这个随着后续文件夹的增长而自动创建,随着进一步的数字 800 的进行
#!/bin/bash
origFolder="/data/rawdata/temp"
destFolder="/data/rawdata/cpp_tr"
NoOfFilesinEachDir=800
###################################################################################################
numberTR=`ls $origFolder | egrep "^A[[:digit:]]{8}\.[[:digit:]]{4}.*bin.gz" | cut -f2 -d',' | cut -d'=' -f2 | sort | uniq | wc -l`
siteuniq=`ls $origFolder | egrep "^A[[:digit:]]{8}\.[[:digit:]]{4}.*bin.gz" | cut -f2 -d',' | cut -d'=' -f2 | sort | uniq`
##Calculate and create folders required to put 800files.
for count in $NoOfFilesinEachDir; do
nn=1
numberofbunch=$((numberTR%count?numberTR/count+1:numberTR/count))
if [[ $numberTR -le $count ]]; then
mkdir "$destFolder/cpptr_$nn"
else [[ $numberTR -gt $count ]];
for (( pp=1; pp<=$numberofbunch; pp++ )); do
mkdir "$destFolder/cpptr_$pp"
done
fi
done
## I am trying to make this list automate for no of folders created above
for number in $NoOfFilesinEachDir; do
kkk=()
#echo $site
read -r -a kkk <<< $siteuniq
lastelement=$(echo "${#siteuniq[@]}")
for (( bb=0; bb<=$number; bb++ )); do
find $origFolder -regextype sed -regex ".*${kkk[bb]}*.*" -exec cp -fp {} $destFolder/cpptr_1 \;
done
for (( cc=801; cc<=1600; cc++ )); do
find $origFolder -regextype sed -regex ".*${kkk[cc]}*.*" -exec cp -fp {} $destFolder/cpptr_2 \;
done
for (( dd=1601; dd<=2400; dd++ )); do
find $origFolder -regextype sed -regex ".*${kkk[dd]}*.*" -exec cp -fp {} $destFolder/cpptr_3 \;
done
for (( dd=2401; dd<=$lastelement; dd++ )); do
find $origFolder -regextype sed -regex ".*${kkk[dd]}*.*" -exec cp -fp {} $destFolder/cpptr_4 \;
done
done
~