加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl 替换文件中的一行

发布时间:2020-12-16 00:07:49 所属栏目:大数据 来源:网络整理
导读:给你个例子 m.txt的内容 5 4 3 2 1 现在把里面的2换成two Perl code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 use ? strict; my ? @old ? =?(); @new ? =?(); ? open ? F,? '+m.txt' ? or? die ? "$!n" ; =?F; ? ? for ? $line ? ( @old )
给你个例子
m.txt的内容
5
4
3
2
1
现在把里面的2换成two
Perl code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use? strict;
my? @old? =?();
@new? =?();
?
open? F,? '+<m.txt'? or? die? "$!n" ;
=?<F>;
?
?
for? $line? ( @old )?{
???? chomp? $line ;??????
???? if? ==? '2' )?{?????
???????? push? @new ,monospace!important; font-size:1em!important; font-style:normal!important; font-weight:normal!important; vertical-align:baseline!important; float:none!important; position:static!important; min-height:inherit!important">'two' ;??
???? }? else? {
;???
}
}
?
seek? ?
print?? F? join? "n" ;
close? F;

修改后的m.txt
5
4
3
two
1
方法有点麻烦。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读