Last active
August 29, 2015 14:19
-
-
Save casspangell/bfd8180c808f143cd1a0 to your computer and use it in GitHub Desktop.
Rename Filename Loop Bash
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 | |
# Rename files in dir to slide_##.pdf with two numerals | |
# Exampe filename: UMB_AR App_AN_041515_FA.33.pdf | |
foo = 0 | |
for f in *.pdf | |
do | |
NEW_NAME="$(echo "$f" | sed 's/\UMB_AR App_AN_041515_FA.//g')" | |
#Find names with 1 char number | |
if [ ${#NEW_NAME} -eq 5 ]; | |
then | |
zero=0 | |
foo=$zero$NEW_NAME | |
else | |
foo=$NEW_NAME | |
fi | |
STR1=slide_ | |
FINAL=$STR1$foo | |
echo $FINAL | |
mv "$f" "$FINAL" | |
done |
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 | |
# Rename files in dir | |
# Filename example slide_slide_30.pdf | |
# Need to remove the first slide_ | |
for f in *.pdf | |
do | |
echo $f | sed 's/^slide_//' | |
foo="$(echo "$f" | sed 's/^slide_//')" | |
echo $foo | |
mv "$f" "$foo" | |
done |
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 | |
# Rename files in dir by subtracting their numerical names | |
#ie 01.pdf will become 0.pdf, 02.pdf will become 1.pdf | |
one=1 | |
for f in *.pdf | |
do | |
file=$(basename "$f") | |
extension=${f##*.} | |
number=${file%.*} | |
#echo $number | |
num=`expr $number - $one` | |
name=$num.pdf | |
echo $name | |
mv "$f" "$name" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment