Skip to content

Instantly share code, notes, and snippets.

@rmariano
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmariano/319ab6967be59e2014e7 to your computer and use it in GitHub Desktop.
Save rmariano/319ab6967be59e2014e7 to your computer and use it in GitHub Desktop.
Shell scripting
#!/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 (marianoanaya@gmail.com)
## @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

A collection of shell scripts for common repetitive tasks, that might come in handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment