|
|
|
|
 如何删除一个文件中的指定行? - stan1ie [ 2005-04-11 01:23 | 291 byte(s)]
 Re: 如何删除一个文件中的指定行? - tiw [ 2005-04-16 00:15 | 48 byte(s)]
 Re: 如何删除一个文件中的指定行? - stan1ie [ 2005-04-20 01:06 | 80 byte(s)]
 Re: 如何删除一个文件中的指定行? - wandys [ 2005-04-11 11:18 | 44 byte(s)]
 Re: 如何删除一个文件中的指定行? - stan1ie [ 2005-04-11 19:25 | 322 byte(s)]
 Re: 如何删除一个文件中的指定行? - stan1ie [ 2005-04-11 16:22 | 691 byte(s)]
 More than one way to do it. - wandys [ 2005-04-11 19:57 | 731 byte(s)]
 Re: More than one way to do it. - stan1ie [ 2005-04-12 15:12 | 10 byte(s)]
|
|
|
|
[Original]
[Print]
[Top]
|
比如文件内容为:
asdf123
sldkfjals 123
lkasjld
dfl'asdkf
sdkjfa
sdlk
asldf123lkdsf
我想在print的时候不包含有123的行,或者整行用正则表达式翻译空掉,咋整?谢谢!
|
|
|
[Original]
[Print]
[Top]
|
|
[Original]
[Print]
[Top]
|
好像稍微有点问题……没成功,而且输出的文件打开后除第一行外,其他的在前面都多了个空格。
my $writefile = "lastwrite.txt";
my $win = "win.txt";
if (open(readfile,"$writefile") || die ("can't open passwdinput")){
@lines = <readfile>;
@lines =~m/123/ && s/.*
//;
if (open (win,">$win") || die ("can't open win")){
print win ("@lines");
}
}
|
|
|
[Original]
[Print]
[Top]
|
|
[Original]
[Print]
[Top]
|
谢谢您了,没搞定,我用另外一个方法凑合上了,写了个bat:
type lastwrite.txt|find /V "123" >all.txt
然后整个sub就改成了:
sub edit
{
system ('edit.bat');
}
狂汗:)
|
|
|
[Original]
[Print]
[Top]
|
|
[Original]
[Print]
[Top]
|
1)
while (<>) {
m/123/ && s/.*
//;
print $_;
}
2) better:
while (<>) {
m/123/ && next;
print $_;
}
3) much better:
while (<>) {
print unless m/123/;
}
4) or by using grep:
print grep(!/123/, <>);
./foo.pl <input >output
or by using the 'grep' command if you like:
$ grep -v 123 <input > output
|
|
|
----
UN*X is user^H^H^H^Hfriend-friendly.
|
|
[Original]
[Print]
[Top]
|
|
|