搜索多个文件,但如果缺少一个文件,我想从输出 + 查找中知道

搜索多个文件,但如果缺少一个文件,我想从输出 + 查找中知道
$ find ./ -name "AABE*"  ## this returns nothing 
$ echo $? 
0

$ find ./ -name "AWGT*"  ## this returns locations of were files matching the criteria
./Atempt3A/AWGT-modified.txt
./Atempt3A/test_will_nov2022/AWGT-modified.txt
./Attempt5_Dec_2022/scripts/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AWGT-modified.txt
$ echo $?
0
    
$ find ./ -type f -name "AWGT*" -o -name "SLIN*" -o -name "AABE*" -o -name "AMDM*" -o -name "ARDE*" -o -name "WTHC*" ## this returns locations of were multiple files matching the criteria
./Atempt3A/AMDM-modified.txt
./Atempt3A/AWGT-modified.txt
./Atempt3A/test_will_nov2022/AWGT-modified.txt
./Atempt3A/WTHC-modified.txt
./Attempt2/164_sites/env_scripts/AMDM-modified.txt
./Attempt2/164_sites/env_scripts/WTHC-modified.txt
./Attempt2/179ish_sites_20220914/AMDM-modified.txt
./Attempt2/179ish_sites_20220914/WTHC-modified.txt
./Attempt5_Dec_2022/again/ARDE-modified.txt
./Attempt5_Dec_2022/again/SLIN-modified.txt
./Attempt5_Dec_2022/scripts/AMDM-modified.txt
./Attempt5_Dec_2022/scripts/AWGT-modified.txt
./Attempt5_Dec_2022/scripts/WTHC-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AMDM-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/ARDE-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/SLIN-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/WTHC-modified.txt
$ echo $?
0

我想要的是输出显示类似这样的内容:找不到“AABE*”,或者有这种影响的内容可以完成吗?

与这个问题相关,但我的答案略有不同 当未找到匹配的文件时,我可以让“find”返回非 0 吗?

EDIT1-答案

$ find ./ -type f -name "AWGT*" -o -name "SLIN*"     -o -name "AZZZ*" -o -name "AMDM*" -o -name "ARDE*" -o -name "AQQQ*" |     perl -pe '
        BEGIN{ our %h; our $error = 0; }
        $h{$1}++ if m/(AWGT|SLIN|AZZZ|AMDM|AQQQ)/;
        END{
            for ("AWGT", "SLIN", "AZZZ", "AMDM", "AQQQ") {
                if ($h{$_} == 0) {
                    $error = 1;
                    warn "cannot find $_\n"
                }

            }
            exit($error)
         }
    '
./Atempt3A/AMDM-modified.txt
./Atempt3A/AWGT-modified.txt
./Atempt3A/test_will_nov2022/AWGT-modified.txt
./Attempt2/164_sites/env_scripts/AMDM-modified.txt
./Attempt2/179ish_sites_20220914/AMDM-modified.txt
./Attempt5_Dec_2022/again/ARDE-modified.txt
./Attempt5_Dec_2022/again/SLIN-modified.txt
./Attempt5_Dec_2022/scripts/AMDM-modified.txt
./Attempt5_Dec_2022/scripts/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AMDM-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/ARDE-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/SLIN-modified.txt
cannot find AZZZ
cannot find AQQQ

答案1

我会做什么:

find ./ -type f -name "AWGT*" -o -name "SLIN*" \
    -o -name "AABE*" -o -name "AMDM*" -o -name "ARDE*" -o -name "WTHC*" |
    perl -pe '
        BEGIN{ our %h; our $error = 0; }
        $h{$1}++ if m/(AWGT|SLIN|AABE|AMDM|WTHC)/;
        END{
            for ("AWGT", "SLIN", "AABE", "AMDM", "WTHC") {
                if ($h{$_} == 0) {
                    $error = 1;
                    warn "cannot find $_\n"
                }
                
            }
            exit($error)
         }
    '

相关内容