替换一个目录下文件中的某个字符串
【按语:学习的过程就是抄袭的过程。所谓的原创不过是把字典里的字和词重新排列组合一下而已;与抄袭者或曰剽窃者的不同在于组成知识体系的元素的粒度不同。原创者的粒度是基本的字和词,抄袭者的粒度是文章或节选的章节。
没有不尊重原作者的意思,以上言论,纯属调侃。
再次感谢原文作者flyboy。】
例如替换目录中所有*.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
阅读(935) | 评论(0) | 转发(0) |