Here is a short script to replace strings with sed easily written in bash.
#!/bin/bash
#Replace string in file of given extension
#argument 1, extension type
#argument 2, old string
#argument 3, new string
EXPECTED_ARGS=3
 
if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` [extension] [old_str] [new_str]"
  echo "Exemple: `basename $0` php old_text new_text"
  exit 1
fi
 
EXTENSION=$1
OLDSTR=$2
NEWSTR=$3
 
#Simply replace string with sed and erase old file
for file in `find . -name "*.$EXTENSION"`
do
  sed -i "s/$OLDSTR/$NEWSTR/g" $file
done
exit $?

The user can specify an extension, as well as the strings to be replaced and to replace.
This is just a memo, nothing serious…

Michael

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

©2010-2013 Michael Paquier All content is ©Copyright of Otacoo.com 2010-2013. Privacy Policy - Terms of Use