Particular line match using regex

前端 未结 4 1035
挽巷
挽巷 2021-01-28 01:09
This script may take a while to run, especially on a busy podmaster.
Generating Syslog TopN list on node for last 3 hours.

        Top 5 hosts for Day: Oct8 between 02:         


        
4条回答
  •  醉酒成梦
    2021-01-28 01:23

    There's nothing wrong with your regex.

    That's just a formatting difference:

    use strict;
    use warnings;
    
    my $data = do {local $/; };
    
    my @ones = $data =~ m/^\s*[1]\s+([\d]+)/mg;
    
    for my $i (0..$#ones) {
        printf "\$%d = %s\n", $i+1, $ones[$i];
    }
    
    __DATA__
            Rank       Number of Alerts Host
            ----       ---------------- ----
            1       3124        abc
            2       2294        bcd
    
    
    
            Rank       Number of Alerts Host
            ----       ---------------- ----
            1       5495        cdf
            2       2625        klm
    
    
            Rank       Number of Alerts Host
            ----       ---------------- ----
            1       2747        lll
            2       876         jjj
    

    Outputs:

    $1 = 3124
    $2 = 5495
    $3 = 2747
    

    live demo

提交回复
热议问题