Last active
December 16, 2015 03:49
-
-
Save pmbuko/5372666 to your computer and use it in GitHub Desktop.
This script will, in the specified directory, find files ending with a space and a 2 -- ' 2' -- and strip that ending off matching files. Read inline comments for more info.
This file contains 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 | |
# Explicitly set the directory you want to operate on here | |
workingPath="/your/path/here" | |
# Set a custom internal field separator to ease handling | |
# of filenames that contain spaces | |
IFS=$'\n' | |
# Identify files that end in ' 2' and tack on our custom | |
# field separator | |
endIn2=$(find "${workingPath}" -regex '.* 2$' | awk '{print $0"\n"}') | |
# Go through the list of files and rename them | |
for oldName in $endIn2; do | |
newName=$(echo "${oldName}" | awk -F' 2' '{print $1}') | |
# show what this script will do | |
echo "\"${oldName}\" <-- will become --> \"${newName}\"" | |
# uncomment the next line after verifying output | |
#mv "${oldName}" "${newName}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment