Chinaunix首页 | 论坛 | 博客
  • 博客访问: 126983
  • 博文数量: 100
  • 博客积分: 1850
  • 博客等级: 上尉
  • 技术积分: 650
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-02 23:52
文章分类

全部博文(100)

文章存档

2016年(1)

2009年(1)

2008年(5)

2007年(11)

2006年(32)

2005年(50)

我的朋友

分类: LINUX

2006-07-01 13:08:37

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