ls -1 dir1/*.hh dir2/*.ii | awk -F"/" '{print $NF}' |awk -F"." '{a[$1]++;b[$0]}END{for(i in a)if(a[i]==1 && b[i".hh"]) print i}'
explanation:
ls -1 dir1/*.hh dir2/*.ii
all the * .hh and * .ii files in both directories are listed above.
awk -F"/" '{print $NF}'
the above will just print the file name, excluding the full path to the file.
awk -F"." '{a[$1]++;b[$0]}END{for(i in a)if(a[i]==1 && b[i".hh"]) print i}'
above will create two associative arrays, one with the file name and one with the exception of the extension. if both hh and ii files exist, the value in the associated array will be 2, if there is only one file, then the value will be 1. So we need an array element whose value is 1, and this must be a header file (.hh) . this can be verified using asso..array b, which is executed in the END block.
source share