Created
October 9, 2013 01:02
-
-
Save nobucshirai/6894496 to your computer and use it in GitHub Desktop.
"mv" command wrapper to change file name using "sed".
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 | |
| #$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