there are around 676 files in a directory and I want to batch every 10 and then remaining 7 files as well for a batch pressing job simultaneously.
I'm trying to pick-up every 10 counter'd files -- batch these files and then move on with the next batch.. after resetting the Counters back to 0;
but what if I am left with remaining [1-9] files like for now I have 7 files which are not falling under ==10 rule .
FILECOUNTER=0;
for filex in `ls`;
do
let "FILECOUNTER++"
FILENAMES="$filex\t$FILENAMES"
if [[ $FILECOUNTER -eq 10 ]]
then
$BATCH_THE_PROCESS `echo -e $FILENAMES`
FILECOUNTER=0;
FILENAMES="";
fi
done
This loop is running fine for files till 670, but I'm missing last 7 files which are not accounted for in the if-else
Can someone please suggest to get a listing for every 10 or less ( if there are less than 10 files remaining)
parms=""
cnt=0
cd /path/to/files
ls | while read fname
do
parms="$parms $fname"
cnt=$(($cnt +1))
if [ $cnt -eq 10 ] ; then
batch /path/to/myjobname parms
cnt=0
parms=""
fi
done
# one answer to your question - run any amount of leftovers:
[ $cnt -gt 0 ] && batch /path/to/myjobname $parms