Created
March 6, 2018 17:02
-
-
Save 2jiwon/00c9481745ad8e4a17eb187ecd2d12bd to your computer and use it in GitHub Desktop.
A Bash Shell Script to replace a string in files of a directory recursively.
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 | |
Files=(`grep -r "\.sgk" ./ | cut -d: -f1 | uniq`) | |
for file in "${Files[@]}" | |
do | |
echo "Filename: $file" | |
grep "\.sgk" "$file" | more | |
done | |
echo "" | |
answer=N | |
echo -n "Is this result right? Do you want to change the string of the files? (y/N)" | |
read answer | |
if [[ "$answer" == [Yy] ]] | |
then | |
for file in "${Files[@]}" | |
¦ do | |
¦ ¦ sed -i "s:\.sgk:\.php:g" "$file" | |
¦ done | |
¦ if [[ $? == "0" ]]; then | |
¦ ¦ echo -e "Done.\n" | |
¦ fi | |
else | |
echo -e "Okay,bye...\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment