分类: Python/Ruby
2013-02-20 17:35:31
1. 脚本实现
#!/usr/bin/perl -w
# replace.pl
$^I = ".bak";
while (<>) {
s/now/just now/g;
print;
}
执行脚本:
perl replace now.txt
将会把now.txt 里的now替换为just now并且产生一个备份文件now.txt.bak
2. perl 命令行实现:
perl -i.bak -pe "s/now/just now/g" now.txt