Created
January 4, 2017 14:00
-
-
Save schluppeck/79bb06783f582d7d7eb77d626d5cc03a to your computer and use it in GitHub Desktop.
remove white spaces in a bunch of files downloaded from moodle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# when downloading from moodle, filenames (incl. zip files) have annoying white spaces in them | |
# | |
# ds 201701 | |
#filetype, e.g. | |
ending=.zip | |
# loop through | |
for i in *${ending}; do | |
# make a new filename without blanks | |
# this will work even when there are NO BLANKS! | |
n=`echo "${i}" | sed 's/[[:blank:]]//g'`; | |
# and if appropriate - move them | |
#NB, then first set of quotation marks is needed, as the filenames still have spaces! | |
mv "${i}" ${n}; | |
if [[ ${ending} == ".zip" ]]; then | |
# cut at first underscore - this is reasonable for us as the submissions are | |
# FirstnameLastname_someAssignment_blablabla.zip | |
fname=`echo ${i} | cut -d _ -f 1` | |
# could cut after first space | |
# fname=`echo ${i} | head -n1 | awk '{print $1;}'` | |
# could convert into shasum - as filename - but loses name info! | |
# fname=`shasum ${n} | awk '{ print $1 }'` | |
cmd="unzip ${n} -d ${fname}" | |
${cmd} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment