使用perl-pe删除文件的第一行

使用perl-pe删除文件的第一行,perl,sed,Perl,Sed,我试图使用perl-pe而不是system&sed-I删除输出文件“bss\u concurrent\u calls.txt”的第一行。我正在使用的服务器是solaris 9(实际上它不识别“sed-I”) 在“中打开我的$file_,无需在此处(或其他任何地方)从Perl调用sed perl-an'print“$F[0]\t$F[2]\n”除非$.==1'\ bss\u concurrent\u calls.txt while(){ 下一步除非$i++; my@columns=split/\s

我试图使用perl-pe而不是system&sed-I删除输出文件“bss\u concurrent\u calls.txt”的第一行。我正在使用的服务器是solaris 9(实际上它不识别“sed-I”)


在“中打开我的$file_,无需在此处(或其他任何地方)从Perl调用sed

perl-an'print“$F[0]\t$F[2]\n”除非$.==1'\
bss\u concurrent\u calls.txt
while(){
下一步除非$i++;
my@columns=split/\s+/,$;
打印$file_out“$columns[0]\t$columns[2]\n”;
}

我喜欢@choroba的答案,但如果您想保留您的程序结构:

use autodie;
open my $file_in,  '<', '/export/home/cassi/4.1-15_HPBX/cfg/LicenseCounters.log';
open my $file_out, '>', 'bss_concurrent_calls.txt';

my $line1 = <$file_in>;  # read the first line
while (<$file_in>) {
    print $file_out join("\t", (split)[0,2]), "\n";
}

close $file_in;
close $file_out;
使用autodie;
在“,”bss_concurrent_calls.txt”中打开我的$file_;
我的$line1=#读第一行
而(){
打印$file\u out join(“\t”,(拆分)[0,2]),“\n”;
}
在中关闭$file_;
关闭$file_;

调用系统的更好方法是使用参数列表:这避免了必须生成/bin/sh来调用命令:
system'sed',1d',bss_concurrent_calls.txt'
为什么不简单地
tail-n+2 bss_concurrent_calls.txt
?只需
标量即可。无需声明variable@Oesor...could你好心地离开了我明白“下一步”是什么,除非$i++;“正在做什么?谢谢。它跳过了第一行。使用全局作用域的undef
$i
,第一次通过循环
$i++
返回0,然后将
$i
增加到1。由于0为false,代码转到下一行。下一次通过时,它返回正整数或true,这意味着
除非true,否则返回下一行。”>从不触发下一个
perl -ane 'print "$F[0]\t$F[2]\n" unless $. == 1' \ 
    < /export/.../LicenseCounters.log > bss_concurrent_calls.txt
while( <$file_in> ) {
    next unless $i++;
    my @columns = split /\s+/, $_;
    print $file_out "$columns[0]\t$columns[2]\n";

}
use autodie;
open my $file_in,  '<', '/export/home/cassi/4.1-15_HPBX/cfg/LicenseCounters.log';
open my $file_out, '>', 'bss_concurrent_calls.txt';

my $line1 = <$file_in>;  # read the first line
while (<$file_in>) {
    print $file_out join("\t", (split)[0,2]), "\n";
}

close $file_in;
close $file_out;