I am required to write a one-time util that does some operation on all the files in a given directory but a list of files in a predefined list. Since the given list is predefined, I am going to hard-code it as an array.Having said that, how to get names of all files that are not in the given array? This can be in any standard unix script(bash, awk, perl).
Get all files but the files in array - Bash
shell script
With bash, you could do:all=(*)except=(file1 file2 notme.txt)only=()IFS=/for file in ${all[@]}; do  case /${except[*]}/ in    (*/$file/*) ;;     # do nothing (exclude)    (*) only+=($file)  # add to the array  esacdonels -ld -- ${only[@]}(that works here for the files in the current directory, but not reliably for globs like all=(*/*) except=(foo/bar) as we use / to join the elements of the array for the look-up).It's based on the fact that ${array[*]} joins the elements of the array with the first character of $IFS (here chosen to be / as it can't otherwise occur in a file name; NUL is a character that can't occur in a file path, but unfortunately bash (contrary to zsh) can't have such a character in its variables). So for each file in $all (here with $file being foo as an example), we do a case /file1/file2/notme.txt/ in (*/foo/*) to check if $file is to be excluded.