这是我的问题,假设我有一个file1.txt内容文件
:
abc..
def..
ghi..
def..
Run Code Online (Sandbox Code Playgroud)
和file2.txt内容的第二个文件:
xxx..
yyy..
zzz..
Run Code Online (Sandbox Code Playgroud)
现在我想复制开始"高清"的所有线file1.txt对file2.txt和追加后"YYY ......"行file2.txt
xxx...
yyy...
def...
def...
zzz...
Run Code Online (Sandbox Code Playgroud)
我对perl很新,我已经尝试为此编写简单的代码,但最终输出只附加在文件的末尾
#!/usr/local/bin/perl -w
use strict;
use warnings;
use vars qw($filecontent $total);
my $file1 = "file1.txt";
open(FILE1, $file1) || die "couldn't open the file!";
open(FILE2, '>>file2.txt') || die "couldn't open the file!";
while($filecontent = <FILE1>){
if ( $filecontent =~ /def/ ) {
chomp($filecontent);
print FILE2 $filecontent ."\n";
#print FILE2 $filecontent ."\n" if $filecontent =~/yyy/; …Run Code Online (Sandbox Code Playgroud) perl ×1