#!/bin/bash
##############################################################################
# $Id: search-replace 774485 2009-05-13 18:35:38Z arkurth $
###############################################################################
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
# This shell script searches and replaces a string in all of the files under
# the path specified.

if [ $# -ne 3 ]
then
  echo "Usage: $0 SEARCH_PATTERN REPLACE_PATTERN SEARCH_PATH"
  exit 1
fi

SEARCH_PATTERN=$1
REPLACE_PATTERN=$2
SEARCH_PATH=$3

echo Replacing $SEARCH_PATTERN with $REPLACE_PATTERN in all files under $SEARCH_PATH
for FILEPATH in `grep -r -l $SEARCH_PATTERN $SEARCH_PATH | grep -v svn` 
do
  echo "replacing $SEARCH_PATTERN with $REPLACE_PATTERN in $FILEPATH" 
  sed -i -e "s/$SEARCH_PATTERN/$REPLACE_PATTERN/g" $FILEPATH
done
exit
