Search code examples
bashfindxargs

bash one-liner/script to execute a command on files that do not have an associated file


The following executes do_x.sh on all files of type a_???.json recursively. However, I would like to do the same on a subset of these files that do not have a corresponding file with the same name and different extension.

 find $PWD -type f -name "a_???.json"  | xargs -I{} do_x.sh {}

How do I say in the same one-liner, do the same but only on the files a_???.json that do not have a corresponding a_???.json done? The following is not a solution for sure:

find $PWD -type f -name "a_???.json" -exclude "a_???.json.done" | xargs -I{} do_x.sh {}
Example
a_111.json
a_112.json
a_111.json.done

So, execute do_x.sh only on a_112.json


Solution

  • To keep the same structure of your script, try this :

    find $PWD -type f -name "a_???.json" -execdir test '!' -f {}.done \; -print | xargs -I{} do_x.sh {}