Skip to content

Instantly share code, notes, and snippets.

@c9s
Created October 19, 2009 10:20
Show Gist options
  • Save c9s/213252 to your computer and use it in GitHub Desktop.
Save c9s/213252 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ -z $1 ]] ; then
cat <<END
Usage: replace_list [path] [ext] [from_list] [replace_list]
END
exit
fi
path=$1
extension=$2
from_list=$3
replace_list=$4
echo Path: $path
echo Extension: $extension
from_index=0
replace_index=0
while read line ; do
from[$from_index]="$line"
from_index=$(($from_index+1))
done < $from_list
echo ${#from[*]} items
while read line ; do
replace[$replace_index]="$line"
from_str=${from[ $replace_index ]}
replace_str=${replace[ $replace_index ]}
echo "$from_str => $replace_str"
find $path -type f -iname $extension | xargs -I{} perl -i.bak -pe "s{$from_str}{$replace_str}g" {}
replace_index=$(($replace_index+1))
done < $replace_list
echo [ Done ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment