A collection of shell scripts for common repetitive tasks, that might come in handy.
Last active
August 29, 2015 14:15
-
-
Save rmariano/319ab6967be59e2014e7 to your computer and use it in GitHub Desktop.
Shell scripting
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 | |
## remove-blanks.sh: Removes the blank spaces on files, by replacing them for dash (-) | |
## (I do not like blank spaces on filenames) | |
## @Author: Mariano Anaya ([email protected]) | |
## @Date: Sat 23 Jun, 2012 - Buenos Aires, Argentina | |
#parameters: remove-blanks.sh <file_type> | |
red='\e[0;31m'; | |
white='\e[0;37m'; | |
black='\e[0;30m'; | |
green='\e[0;32m'; | |
color_off='\e[0m'; | |
target="."; | |
mode="p"; # 't': test mode (development) , 'p': production mode | |
if [ "$1" == "" ]; then | |
file_type="pdf"; | |
elif [ "$1" == "all" ]; then | |
file_type="*"; | |
else | |
file_type=$1; | |
fi | |
for file in *.$file_type; do | |
new=$(echo $file | sed 's/\ /-/g' ); | |
#now remove the triple dashes (in case <blank>-<blank> becomes "---" | |
new=$(echo $new | sed 's/---/-/g' ); | |
if [ "$file" != "$new" ]; then | |
if [ "$mode" == "p" ]; then | |
mv "$file" "$new" | |
echo -e "$file${red} WAS REPLACED BY-> ${color_off}$new"; | |
else | |
echo -e "${green} [Test-mode] - ${color_off}$file${red} Would be replaced by -> ${color_off}$new " | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment