Perl:如何在新文本文件中编写脚本输出

Perl:如何在新文本文件中编写脚本输出,perl,Perl,首先,我是perl的noob,我试图在互联网上找到这个问题的答案,但无法得到(或理解)。。。 所以,我有一个脚本,它扫描一个文本文件并写入所有行,除了以a开头的行 #!/usr/bin/perl use strict; use warnings; open (my $file, "<", "/file.txt") or die "cannot open < file.txt $!"; while (<$file>) { unless (/^A/) {

首先,我是perl的noob,我试图在互联网上找到这个问题的答案,但无法得到(或理解)。。。 所以,我有一个脚本,它扫描一个文本文件并写入所有行,除了以a开头的行

#!/usr/bin/perl
use strict;
use warnings;
open (my $file, "<", "/file.txt") or die "cannot open < file.txt $!";
while (<$file>) {
    unless (/^A/) {
        print;
    }
}  
#/usr/bin/perl
严格使用;
使用警告;

打开(我的$file,“只需打开另一个文件并将数据打印到其中

#!/usr/bin/env perl
use strict;
use warnings;

my $infile  = 'input.txt';
my $outfile = 'output.txt';

open my $infh,  "<", $infile  or die "Can't open $infile: $!";
open my $outfh, ">", $outfile or die "Can't open $outfile: $!";

while (<$infh>) {
    print $outfh $_ unless /^A/;
}

close($infh);
close($outfh);

perl yourscript.pl>output.txt
如果您使用的是linux,您也可以只执行
grep-v“^A”file.txt>output.txt
。或者
perl-ne'print,除非(/^A/)”>output.txt
,谢谢大家!我帮了大忙!