Skip to content

Instantly share code, notes, and snippets.

@thegabriele97
Last active January 30, 2019 11:12
Show Gist options
  • Save thegabriele97/bedab88deaeaedceeb844d3b442eb2b5 to your computer and use it in GitHub Desktop.
Save thegabriele97/bedab88deaeaedceeb844d3b442eb2b5 to your computer and use it in GitHub Desktop.
#!/bin/bash
if ! [ $# -eq 1 ]; then
exit 1
fi
for file in $(ls $1 | grep '-'); do
str=""
cnt=$(echo $file | cut -f1 -d'.' | wc -c)
i=1
while [ $i -lt $cnt ]; do
char=$(echo $file | cut -f1 -d'.' | cut -b$i)
if [ "$char" = "-" ]; then
char='/'
fi
str="$str$char"
i=$[$i+1]
done
ext=$(echo $file | cut -f2 -d'.')
entire="${str}.${ext}"
path=$(dirname $entire)
mkdir -p $1/$path
cp "$1/$file" "$1/$path/$(basename $entire)"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment