Skip to content

Instantly share code, notes, and snippets.

@liquidz
Created October 23, 2008 06:34
Show Gist options
  • Select an option

  • Save liquidz/18937 to your computer and use it in GitHub Desktop.

Select an option

Save liquidz/18937 to your computer and use it in GitHub Desktop.
#!/bin/sh
# script for replacing multiple files
#
# usage: ./replace.sh [directory] [filter] [before] [after]
#
# ex) replace "e" to "a" for all htm/html file in current dir
# # ./replace . 'html?$' e o
if [ $# -eq 0 ]
then
echo "usage: ./replace.sh [directory] [filter] [before] [after]"
echo ""
echo "ex) replace 'e' to 'a' for all htm/html file in current dir"
echo " # ./replace . 'html?$' e o"
else
list=`find $1 | egrep -e $2`
for file in ${list[@]}
do
sed s/$3/$4/g $file > "$file.tmp"
mv $file "$file.back"
mv "$file.tmp" $file
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment