Skip to content

Instantly share code, notes, and snippets.

@schluppeck
Last active January 9, 2020 20:22
Show Gist options
  • Save schluppeck/30164a20b64fba8951b2c7847cf4b450 to your computer and use it in GitHub Desktop.
Save schluppeck/30164a20b64fba8951b2c7847cf4b450 to your computer and use it in GitHub Desktop.
using a bash look and awk to rename some badly formed file names
# dealing with OneDrive filesep issues...
#
# ds 2020-06-09, coffee break unix hacking.
# shell loop for moving files with windows sep \ into folders with filesep /
# for example: files called Carblblblabl\ACTUAL_FILE.jpg
# should go into folder Carblblblabl/ACTUAL_FILE.jpg
# idea. use AWK with field sep \ to split into two strings.
# then paste them together with / and use in unix/mv
for f in `ls -1 Car*.{jpg,mat}` ; do
g=$(echo $f | awk -F '\' '{print $1 "/" $2}')
echo "moving ${f} to ${g}"
mv ${f} ${g}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment