I have a folder contains files name as: xxx.get.txt and xxx.resp.txt

   xxx.get.txt, xxx.resp.txt
   yyy.get.txt, yyy.resp.txt
   zzz.get.txt, zzz.resp.txt, etc

each prefix xxx should have two corresponding files, .get.txt and .resp.txt

However, now I calculate the number of .get.txt and the number of .resp.txt files, they are not equal, there're ten more .get.txt. I want to find out, which .get.txt files do not have ´.resp.txt´ file

Is it possible?

Many thanks!


Iterate all the get.txt files and check if the corresponding resp.txt files exist.

for file in *.get.txt; do 
    [[ -e ${file%.get.txt}.resp.txt ]] || echo "$file is missing resp"; 

${file%.get.txt} is the same as $file except, .get.txt is removed from the end (if it has that string at the end).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.