【发布时间】:2014-04-22 20:08:31
【问题描述】:
我正在尝试使用 perl -pe 而不是 system & sed -i 来删除输出文件“bss_concurrent_calls.txt”的第一行。我使用的服务器是 solaris 9(实际上它不识别“sed -i”)
open my $file_in, "<", "/export/home/cassi/4.1-15_HPBX/cfg/LicenseCounters.log" or die($!);
open my $file_out, '>', 'bss_concurrent_calls.txt' or die $!;
while( <$file_in> ) {
my @columns = split /\s+/, $_;
print $file_out "$columns[0]\t$columns[2]\n";
}
system('sed "1d" bss_concurrent_calls.txt');
close $file_in;
close $file_out or die $!;
【问题讨论】:
-
调用系统的更好方法是使用参数列表:这样可以避免产生 /bin/sh 来调用命令:
system 'sed', '1d', 'bss_concurrent_calls.txt'; -
为什么不简单地
tail -n +2 bss_concurrent_calls.txt?