Skip to content

Instantly share code, notes, and snippets.

@nobucshirai
Created October 9, 2013 01:02
Show Gist options
  • Save nobucshirai/6894496 to your computer and use it in GitHub Desktop.
Save nobucshirai/6894496 to your computer and use it in GitHub Desktop.
"mv" command wrapper to change file name using "sed".
#!/bin/bash
#$Id: name_sedder.sh,v 1.1 2012-10-13 09:13:03+09 shirai Exp $
before="$1"
after="$2"
old_name=$3
main(){
check_args $@
new_name="`echo $old_name | sed "s/$before/$after/g" `"
mv -vi $old_name $new_name
}
check_args(){
if [[ "$before" == "" || "$after" == "" || ! -e $old_name ]];then
echo " PLEASE INPUT TWO WORDS AND FILE NAME" >&2
echo "Usage: $0 present_name new_name file_name" >&2
exit 1
fi
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment