Last active
May 19, 2016 21:01
-
-
Save seanriceaz/e36ade67b67163ce04f1c6f74f1c6576 to your computer and use it in GitHub Desktop.
The purpose of this script is to churn through a directory with a bunch of files in it that have been misnamed. It will rename files similar to a find and replace.
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
#!/bin/bash | |
# The purpose of this script is to churn through a directory with a bunch of | |
# files in it that have been misnamed. It will rename files similar to a find | |
# and replace. | |
#Find this string | |
FINDTHIS="--" | |
#Replace it with this string | |
REPLACEWITH="-" | |
for file in ./**; do | |
if [[ -f "$file" ]]; then | |
dirname="${file%/*}/" | |
basename="${file:${#dirname}}" | |
#Find and Replace | |
newname="${basename//$FINDTHIS/$REPLACEWITH}" | |
#Concatenate | |
#newname="STRINGTOSTARTWITH--$basename" | |
#regex Rearrange | |
#newname=$(sed 's/^\(.*--\)\(.*-\)\(.*-\)\(.*-\)\(.*-\)\(.*$\)/\1\2to-\4\3\5\6/' <<< $basename) | |
#echo $newname | |
mv "$file" "$dirname$newname" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding more options like concatenating and using a regex to rearrange the file name