Skip to content

Instantly share code, notes, and snippets.

@masakiplus
Created June 28, 2015 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masakiplus/59b739749851766564ec to your computer and use it in GitHub Desktop.
Save masakiplus/59b739749851766564ec to your computer and use it in GitHub Desktop.
#!/bin/bash
itemcount=0
subcount=1
for a in `ls G*.JPG 2> /dev/null`
do
echo "$a"
lastproduct="$productid"
productid=`echo "$a" | gawk '{print substr($a, 9,6)}'`
colorid=`echo "$a" | gawk '{print substr($a, 16,2)}'`
echo "last was "$lastproduct
echo "current is "$productid
echo "color is "$colorid
if [ "$lastproduct" != "$productid" ]
then
itemcount=0
fi
mkdir $productid/main -p
mkdir $productid/color -p
if [ $itemcount -eq 0 ]
then
cp $a $productid/main/0.JPG
else
cp $a $productid/color/$colorid.JPG
fi
itemcount=`expr $itemcount + 1`
echo $itemcount
done
for b in `ls *sub*.jpg 2> /dev/null`
do
echo "$b"
lastproduct="$productid"
productid=`echo "$b" | gawk '{print substr($b, 1,6)}'`
echo "last was "$lastproduct
echo "current is "$productid
if [ "$lastproduct" != "$productid" ]
then
subcount=1
fi
mkdir $productid/main -p
cp $b $productid/main/$subcount.JPG
subcount=`expr $subcount + 1`
echo $subcount
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment