#!/bin/sh [ -z "$1" -o -z "$2" ] && { echo "" echo "usage:" echo "strrepl [--dry-run|-d] \"start_dir\" \"search_for\" \"replace_with\"" echo "" exit 1 } DOING="CHANGING" [ "$1" = "-d" -o "$1" = "--dry-run" ] && { echo "" echo "Dry-running mode requested. Only lookup is performed, NO replacement!" echo "" DOING="LOOKING UP" shift } [ ! -d "$1" ] && { echo "Initial dir $1 does not exist!" exit 2 } TEMP="/tmp/strrepl.$RANDOM" ### does the job under AIX and LINUX ### escape containing slashes for the later coming sed ### SEARCH=`echo $2 | awk '{gsub(/\//,"\\\\/"); print $0}'` REPLACE=`echo $3 | awk '{gsub(/\//,"\\\\/"); print $0}'` for F in `find "$1" -name '.svn' -prune -o -type f -exec grep -il "$SEARCH" {} \;` do file $F | grep -qiE 'text|s[ck]ript' || continue echo "$DOING IN: $F" && [ "$DOING" = "CHANGING" ] && \ cat $F | sed "s/$SEARCH/$REPLACE/g" > $TEMP && cat $TEMP > $F && rm -f $TEMP done