проверка файла журнала в Perl

Использование grep с PCRE:

$ grep -Po '.*(?=\s+[^\s]+$)' file.txt 
1223 1234 1323 ... 2222
1233 1234 1233 ... 3444
0000 5553 3455 ... 2334

Использование GNU sed:

$ sed -r 's/(.*)\s+[^\s]+$/\1/' file.txt 
1223 1234 1323 ... 2222
1233 1234 1233 ... 3444
0000 5553 3455 ... 2334
0
20.02.2018, 11:20
1 ответ

Podrías simplemente usarfind:

find. -type f -size 0 -exec echo "The logfile has a 0 size: {}" \;

find. -type f ! -size 0 -exec echo "The logfile does not have a 0 size: {}" \;

Operl:

#!/usr/bin/perl --
use File::Find;

# directory to start looking for log files
my $dir = '/tmp/a';

# search base directory and call subroutine for each file found
find(\&size_check, $dir);

# subroutine to be called by find
sub size_check{
        # check filename matches regex and is a file (not directory)
        if($_ =~ /^.*\.log$/ and -f $_){
                # call stat and put data into an array
                my @stat = stat($_);

                # check to see if the size is zero
                if($stat[7] == 0){
                        print $_. " has a size of 0\n";
                }else{
                        print $_. " has a ". $stat[7]. " size\n";
                }
        }
}
4
28.01.2020, 02:18

Теги

Похожие вопросы