I am not sure if you can do comparison of this kind with find
. However, you can try something like:
Step 1: Create a file by redirecting the output of your find
command.
$ ls -lart
total 0
drwxr-xr-x 12 jaypalsingh staff 408 Jun 19 00:53 ..
drwxr-xr-x 2 jaypalsingh staff 68 Jun 19 00:53 .
$ touch .help .yeah .notinmydictionary
$ ls -lart
total 0
drwxr-xr-x 12 jaypalsingh staff 408 Jun 19 00:53 ..
-rw-r--r-- 1 jaypalsingh staff 0 Jun 19 00:54 .yeah
-rw-r--r-- 1 jaypalsingh staff 0 Jun 19 00:54 .notinmydictionary
-rw-r--r-- 1 jaypalsingh staff 0 Jun 19 00:54 .help
drwxr-xr-x 5 jaypalsingh staff 170 Jun 19 00:54 .
$ find . \( -iname '*~' -o -iname '.*' \) -type f > myhiddenfile.list
$ cat myhiddenfile.list
./.help
./.notinmydictionary
./.yeah
Step 2: Run the following awk
command
$ awk -F'/' 'NR==FNR{a[substr($NF,2)]=$0;next}{for(x in a){if(x == $1)system("rm \-i "a[x])}}' myhiddenfile.list /usr/share/dict/words
remove ./.help? y
remove ./.yeah? y
$ ls -lart
total 8
drwxr-xr-x 12 jaypalsingh staff 408 Jun 19 00:53 ..
-rw-r--r-- 1 jaypalsingh staff 0 Jun 19 00:54 .notinmydictionary
-rw-r--r-- 1 jaypalsingh staff 37 Jun 19 00:54 myhiddenfile.list
drwxr-xr-x 4 jaypalsingh staff 136 Jun 19 01:07 .
Explanation of awk
command:
# Set the field separator to "/"
awk -F'/' '
NR==FNR {
# Slurp your hidden file list in to an array (index is filename;value is complete path)
a[substr($NF,2)]=$0
# Keep doing this action until all files are stored in array
next
}
{
# Iterate over the array
for(x in a) {
# If the filename matches a word in your dictionary
if(x == $1) {
# execute the rm command to delete it
system("rm \-i "a[x])
}
}
}' myhiddenfile.list /usr/share/dict/words
Note: This will work for filename without extensions. For filenames with extensions like .help.txt
will need additional steps to parse the file name for performing lookups against dictionary.