Skip to main content
added 653 characters in body
Source Link
Stéphane Chazelas
  • 586.2k
  • 96
  • 1.1k
  • 1.7k

With the zsh shell:

set -o extendedglob searchdir=/volume2 filename=list-in.txt names=( ${(f)"$(<$filename)"} ) files=( $searchdir/**/(#i)(${(~j[|])names:r}).*(ND.) ) print -rC1 -- $files 

In addition to case insensitive matching enabled with (#i) here, you can also enable approximate matching. For instance (#a2) allowing matches with up to 2 errors (omissions, insertions, transposition, different character).

  • $(<file) expands to the contents of the file. Here it's quoted to prevent IFS-spitting.
  • ${(f)expansion} splits the expansion on line feeds.
  • ${file:r} expands to the rootname of the file (extension removed). When applied to an array, that applies to all the elements.
  • ${(j[|])array} joins the array elements with |. With ~, that | is treated as a glob operator (alternation).
  • **/ matches any level of subdirectories (including 0).
  • (ND.): glob qualifiers:
  • Nullglob: no error if there's no match
  • Dotglob: also look for hidden files
  • . matches only regular files (like the -type f of find).

With the zsh shell:

set -o extendedglob searchdir=/volume2 filename=list-in.txt names=( ${(f)"$(<$filename)" ) files=( $searchdir/**/(#i)(${(~j[|])names:r}).*(ND.) ) print -rC1 -- $files 

In addition to case insensitive matching enabled with (#i) here, you can also enable approximate matching. For instance (#a2) allowing matches with up to 2 errors (omissions, insertions, transposition, different character).

With the zsh shell:

set -o extendedglob searchdir=/volume2 filename=list-in.txt names=( ${(f)"$(<$filename)"} ) files=( $searchdir/**/(#i)(${(~j[|])names:r}).*(ND.) ) print -rC1 -- $files 

In addition to case insensitive matching enabled with (#i) here, you can also enable approximate matching. For instance (#a2) allowing matches with up to 2 errors (omissions, insertions, transposition, different character).

  • $(<file) expands to the contents of the file. Here it's quoted to prevent IFS-spitting.
  • ${(f)expansion} splits the expansion on line feeds.
  • ${file:r} expands to the rootname of the file (extension removed). When applied to an array, that applies to all the elements.
  • ${(j[|])array} joins the array elements with |. With ~, that | is treated as a glob operator (alternation).
  • **/ matches any level of subdirectories (including 0).
  • (ND.): glob qualifiers:
  • Nullglob: no error if there's no match
  • Dotglob: also look for hidden files
  • . matches only regular files (like the -type f of find).
Source Link
Stéphane Chazelas
  • 586.2k
  • 96
  • 1.1k
  • 1.7k

With the zsh shell:

set -o extendedglob searchdir=/volume2 filename=list-in.txt names=( ${(f)"$(<$filename)" ) files=( $searchdir/**/(#i)(${(~j[|])names:r}).*(ND.) ) print -rC1 -- $files 

In addition to case insensitive matching enabled with (#i) here, you can also enable approximate matching. For instance (#a2) allowing matches with up to 2 errors (omissions, insertions, transposition, different character).