regex help on unix df

前端 未结 7 1885
耶瑟儿~
耶瑟儿~ 2020-12-02 01:22

I need some help tweaking my code to look for another attribute in this unix df output:

Ex.

Filesystem     Size    Used   Avail Capacity         


        
7条回答
  •  情深已故
    2020-12-02 01:45

    I think it is probably best to split the lines, skipping the first line. Since you don't mind using @df and $df, neither do I:

    my @df = qx(df -k /tmp);
    shift @df;                # Lose df heading line
    foreach my $df (@df)
    {
        my($system, $size, $used, $avail, $capacity, $mount) = split / +/, $df;
        ....
    }
    

    This gives you all the fields at once. Now you just need to interpret the 'G' and lose the '%', etc.

提交回复
热议问题