例如替换目录中所有*.html文件中的"test"为"test123".
代码如下:
#!/bin/sh
#replace_string.sh - replace string in files under the same directory
#Example Usage: ./replace_sting.sh "*.html" test test123
#Author: Kevin Zhou
#Date: 2006/4/13
usage()
{
echo "./replace_string \"file_type\" src_string dst_string"
echo "Exapmle: ./replace_string \"*\" test test123"
exit
}
if [ -z $2 ]; then
usage
fi
if [ -z $3 ]; then
usage
fi
for f in $1; do
echo "sed s/$2/$3/ $f > $f.bak"
echo "mv -f $f.bak $f"
done
阅读(2340) | 评论(0) | 转发(0) |