Linux 当出现“时跳过行”;perl-n“;
Linux 当出现“时跳过行”;perl-n“;,linux,perl,unix,command-line,Linux,Perl,Unix,Command Line,-n参数使Perl在程序周围放置一个循环,这使它在文件名参数上迭代,有点像sed-n或awk 现在,是否可以使用-n,在脚本中提前跳过并抓取一些即将出现的行 #!/usr/bin/perl -wn if (/my case/) { # Skip two lines <>; <>; # Do something with the line just read. } #/usr/bin/perl-wn 如果(/我的情况/){ #跳过两行 ; ; #用这句话做点
-n
参数使Perl在程序周围放置一个循环,这使它在文件名参数上迭代,有点像sed-n
或awk
现在,是否可以使用-n
,在脚本中提前跳过并抓取一些即将出现的行
#!/usr/bin/perl -wn
if (/my case/) {
# Skip two lines
<>; <>;
# Do something with the line just read.
}
#/usr/bin/perl-wn
如果(/我的情况/){
#跳过两行
; ;
#用这句话做点什么,读一下。
}
上述情况对我不起作用<代码>$\u卡在同一行/内容上 这对我很有用:
perl -wE 'say for 1..10' | perl -ne 'if (/2/) { <>; <>; print "!$_" } else { print }'
1
!2
5
6
7
8
9
10
perl-wE'say for 1..10'| perl-ne'if(/2/){;;print“!$"}else{print}”
1.
!2.
5.
6.
7.
8.
9
10
如果要处理接下来的两行,请将它们存储在变量中
$line1 = <>; $line2 = <>;
$line1=$第2行=;
本身不会填充$\uuu
-仅在的特殊情况下,而()
它对我有效:
perl -wE 'say for 1..10' | perl -ne 'if (/2/) { <>; <>; print "!$_" } else { print }'
1
!2
5
6
7
8
9
10
perl-wE'say for 1..10'| perl-ne'if(/2/){;;print“!$"}else{print}”
1.
!2.
5.
6.
7.
8.
9
10
如果要处理接下来的两行,请将它们存储在变量中
$line1 = <>; $line2 = <>;
$line1=$第2行=;
本身不会填充$\uu
-仅在的特殊情况下,而()
另一种方法是使用滑动窗口缓冲区
perl -ne'
push @buf, $_;
next if @buf <= 3;
shift(@buf);
if ($buf[0] =~ /c/) {
my $line1 = $buf[1];
my $line2 = $buf[2];
...
}
'
perl-ne'
按@buf,$\ux;
接下来,如果@buf另一种方法是使用滑动窗口缓冲区
perl -ne'
push @buf, $_;
next if @buf <= 3;
shift(@buf);
if ($buf[0] =~ /c/) {
my $line1 = $buf[1];
my $line2 = $buf[2];
...
}
'
perl-ne'
按@buf,$\ux;
下一步,如果@buf”本身没有填充$\uz,则只在while()的特殊情况下填充。“,啊,这就是我的原因。谢谢“它本身并没有填充$\仅在while()的特殊情况下。”啊,这就是我的原因。谢谢