要分析文件的awk

时间:2013-04-14 02:29:58

标签: perl

需要一些帮助 这就是我所拥有和想做的事情 这是我的文件,名为file.txt

Sequences   times       Ip1     ip2     Protocol        info
1       2   10.18.19.12 12.29.29.18 udp     hsahdsdd
2       4   10.13.15.67 12.28.29.19 tcp     blabla
3       7   10.12.27.28 12.17.281.19    udp     hkkkljkl

我想(使用Awk)

  • 计算我有多少行并打印该信息+在名为protocol.tx的输出文件中找到的所有协议名称
  • 计算IP1行并在另一个名为ip.txt的输出文件中添加所有Ip的liste

由于 我在这里尝试

#!/usr/bin/perl
$fname = $ARGV[0];
open(FILE, $fname) || die ("cant read \n");
while($ligne=<FILE>)
{
chop ($ligne);
my ($No, $time, $Ip1, $Ip2, $Proto, $info) = split (/ /, $ligne_);
}
system("awk '{print \$6}' $fname");
system ("awk 'END {print NR}' $fname") >line.txt;

1 个答案:

答案 0 :(得分:3)

system的那种形式采用shell命令,所以

use autodie qw( system );
use String::ShellQuote qw( shell_quote );

system(shell_quote('awk', 'END {print NR}', $fname) . ">line.txt");

但是在Perl中使用awk来完成这项琐碎的工作是很愚蠢的。

相关问题