如何给指定的行添加字符~

如何给指定的行添加字符~

如何给指定的行添加字符~
文本:
hjioajfoiafjaeofjo
14486486468464
在文本中查找hjioajfoiafjaeofjo行,然后在下面添加一行字符~
结果:
hjioajfoiafjaeofjo 查找这一行,
e3e3e3e3e3e3e 添加这一行
14486486468464
perl one-liner
regex + oneliner 是这类问题的通用解决方案,仔细读完 qiang 翻译的文章(wiki里面), thanks for reading
open IN
open IN, "my_file";
open OUT, ">my_new_file";

while (<IN>){
print OUT $_;
print OUT "your_words\n" if /your_pattern/;
}

btw:how to make this a one-liner? I'm not familiar with that. Any one tell me?




   

klaus----p...
klaus

perl -ne 'print;print "another line\n" if /hello/' oldfile > newfile 或者

perl -i -pe 's/line/line\nAnother line/' file

perldoc perlrun 或者看看我翻译的那篇 Perl命令行应用介绍 http://xrl.us/fz8u