Score:0

searching for multiple files, but if one file is missing I want to know from the output + find

us flag
$ 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

What I want is the output to show something like: cannot find "AABE*" , or something to this affect can this be done?

related to this question but mine is slighly different Can I make `find` return non-0 when no matching files are found?

EDIT1-Answer

$ 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
Gilles Quenot avatar
cn flag
If an answer solves your problem, please accept it by clicking the large check mark (✓) next to it and optionally also up-vote it (up-voting requires at least 15 reputation points). If you found other answers helpful, please up-vote them. Accepting and up-voting helps future readers. Please see [the relevant help-center article](https://stackoverflow.com/help/someone-answers)
Score:1
cn flag

What I would do:

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)
         }
    '
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.