什么';s相当于sed-n';np';perl文件

什么';s相当于sed-n';np';perl文件,perl,sed,Perl,Sed,通过sed,可以从文件中获取第n行 sed -n '40p' file; A=$(sed -n '40p' file); 这在perl中的等价物是什么 perl -ne '$. ==40 and print' file 或者,您可以跳过小于40行的行,打印所需行,并停止文件处理 perl -ne 'next if $. <40; print; last' file perl-ne'next if$。 或者,您可以跳过小于40行的行,打印所需行,并停止文件处理 perl -ne 'ne

通过sed,可以从文件中获取第n行

sed -n '40p' file;
A=$(sed -n '40p' file);
这在perl中的等价物是什么

perl -ne '$. ==40 and print' file
或者,您可以跳过小于40行的行,打印所需行,并停止文件处理

perl -ne 'next if $. <40; print; last' file
perl-ne'next if$。
或者,您可以跳过小于40行的行,打印所需行,并停止文件处理

perl -ne 'next if $. <40; print; last' file
perl-ne'next if$ 这可能是一个

perl -ne 'print if $. == 40'
$。
是当前输入流的行号。

这可能是一个

perl -ne 'print if $. == 40'

$。
是当前输入流的行号。

如果要将其分配给数组或定标器变量,该怎么办?@computer10
$line=$\ucode>而不是
打印
,如果要分配给某个变量。顺便提一下你想分配给shell变量吗?我想把它分配给perl脚本中的变量。这相当于
sed-n'40pq'
:)我没有意识到这实际上有相当多的作用。如果我想把它分配给数组或定标器变量怎么办?如果你想分配给某个变量,可以使用@computer10
$line=$\ucode>而不是
print
变量顺便说一句,您想分配给shell变量吗?我想分配给perl脚本中的变量。这相当于
sed-n'40pq'
:)我没有意识到这实际上有很多作用。请注意,如果您想读取特定行,最好退出,例如,改用
sed-n'40pq'
。请注意,如果您想阅读特定行,最好退出,即改用
sed-n'40pq'