2017-04-12 21 views
-1

我有一些存储在数组中的值如下,现在我需要对属性值进行一些检查,建议我如何在Perl中继续。如何awk perl数组的值?

@ arr1 =`cat passwd.txt | tr'''\ n'| egrep -i“maxage | minage”| sort'`;

阵列ARR1含有作为“最大生存周期= 0 MINAGE = 0”

在这方面,我需要执行如果上最大生存周期的值条件,有像下面任何方式信息,建议我如我我是perl的新手。

if (@arr1[0]|awk -F= '{print $2}' == 0) { printf "Then print task done"; }

+1

您能否给我们一些_example_数据。因为这是一个非常糟糕的方式,所以你可以使用perl来完成整个事情。 – Sobrique

+0

请显示'passwd.txt'文件。 –

+0

passwd.txt文件在aix操作系统中具有“#lsuser root”的输出信息。我刚刚进入一个文件进行实验,实际上我需要使用该命令。 –

回答

0

你可以试试这个?

@arr1 = `cat passwd.txt | tr ' ' '\n' | grep -i "maxage|minage"| sort`; 
$x = `$arr1[0] | awk -F= {print $2}`; // maybe $3 is true index 
if (x == 0) 
    { 
     print "Then print task done"; 
    } 
1

您可以在Perl中完成整个过程。例如:

use feature qw(say); 
use strict; 
use warnings; 

my $fn = 'passwd.txt'; 
open (my $fh, '<', $fn) or die "Could not open file '$fn': $!"; 
my @arr1 = sort grep /maxage|minage/i, split ' ', <$fh>; 
close $fh; 
if ((split /=/, shift @arr1)[1] == 0) { 
    say "done"; 
}