将几行从一个文件复制到另一个文件



这是我的问题,假设我有一个包含内容的文件file1.txt

abc 
def ->[
sff 
ghi 
]
dqq

现在我想从sffghifile1.txt复制到file2.txt末尾的所有行

即以下行应添加到file2.txt

sff
ghi

这就是我所拥有的。建议我而不是"最后",我应该使用什么来满足我的要求:

My $fh=”file1.txt”;
my @lines = read_file($fh);
while ( my $line = shift @lines) {
next unless ($line =~ m/def/);
last; # this code will write till end of file i.e. dqq
}
append_file('file2.txt', @lines);

这里是

while(<DATA>){
print $_ if /sff/ ... /ghi/
}

__DATA__
abc 
def ->[
sff 
l1
l2
ghi 
]
dqq

my $fh 1 = "file1.txt";

使用文件::Slurp;

$search 1 = "开始";

$search 2 = "结束";

打开(写入,">>",$new);

打开 (fh,"<","$fh 1");

而() {

推送 @array,$_ if/$search 1/../$search 2/;

}

关闭(FH);

append_file('file2.txt',@array);

相关内容

最新更新