Perl - 批量替换
来源:互联网 发布:重庆sem优化 编辑:程序博客网 时间:2024/04/30 22:36
今天同事碰到一个问题,要我帮忙。
具体需求是这样的,有很多html 文件,需要替换文件中的某些内容。要写一个替换的工具进行批量替换。
1,查找所有标签,属性 class 中含有 bcms-btn 的,在class 属性前添加 fid="@@AID@@" 这个自定义的属性。
2,查找所有表情,属性 class 中含有 bcms-form-item的,在 class 前添加 fid="@@FID@@" 这个自定义属性。
一,以下是使用 perl -pi -e '$exp' 进行替换的命令
1,perl -pi -e 's|class="(.*/bcms-btn/b.*)"|fid="/@/@AID/@/@" class="$1"|g' `find inc/ -iname "*.html"`
2,perl -pi -e 's|class="(.*/bcms-form-item/b.*)"|fid="/@/@FID/@/@" class="$1"|g' `find inc/ -iname "*.html"`
当然,后面的find 也可以放在前面来,写成
find inc/ -iname "*.html" | xarge perl -pi -e '$exp'
这样的格式!!
二, 还可以使用 sed -i 's/aaa/bbb/g' $file
1,sed -i 's/class="/(.*/bcms-btn/b.*/)"/fid="/@/@AID/@/@" class="/1"/g' `find inc/ -iname "*.html"`
2,sed -i 's/class="/(.*/bcms-form-item/b.*/)"/fid="/@/@FID/@/@" class="/1"/g' `find inc/ -iname "*.html"`
同样,可以将 find 提前。
- Perl - 批量替换
- perl批量替换字符
- Perl]文字/代码批量替换工具 [转]
- linux perl 批量替换文件内容
- perl命令批量替换文件内容
- Linux下用perl批量替换文本文件的内容
- perl 替换
- linux perl shell perl vi grep awk xargs 批量替换(转载)
- Linux 批量字符串替换命令(sed, perl )与vi文本下字符替换命令
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- linux批量替换文件内容3种方法(perl,sed,shell)
- Perl 正则表达式替换
- Top 10 Javascript Framework
- FSDK_GetImageWidth Function
- 111
- data abort 内核调试错误分析
- 中国人、美国人和日本人的故事
- Perl - 批量替换
- 复旦博士生待遇明升暗降
- Python项目版本规范
- Symbian中声音处理
- 云计算-----图
- Android 软件安装程序(*.apk)的结构分析、反编译以及汉化
- NetBeans
- VC剪切板
- Selenium 的getEval 和runScript 方法的异同