Recursively contrast directory materials by name, overlooking documents expansions

I have a directory having concerning 7,000 songs files. I made use of unsatisfactory to recursively re - inscribe all files in it to a different directory, outputting all files with the very same loved one course and also documents name. The result files have a.mp3 expansion, yet several of the input files had various expansions (. wma,. aac, etc).

I can see that there is a documents matter distinction of ~ 100 files missing out on in the result directory. What I intend to do is run a contrast of both directory sites and also get a checklist of the files that exist in the resource, yet not in the location. This would certainly be straightforward adequate other than I require to overlook distinctions in documents expansion.

I've attempted making use of rsync with completely dry - run activated yet I could not identify a means to overlook documents expansions. I've additionally attempted diff yet was incapable to locate an alternative to just examine by name yet overlook documents expansions. I began assuming I can simply do a recursive ls on both directory sites, remove the documents expansions, and afterwards contrast the results, yet I actually have no suggestion on where to begin with changing the ls result making use of sed or awk.

2019-05-13 05:49:21
Source Share
Answers: 1

To see a listing, below are 2 versions, one that recurses right into subdirectories and also one that does not. All usage syntax details to bash, ksh and also zsh.

comm -3 <(cd source && find -type f | sed 's/\.[^.]*$//' | sort) \
        <(cd dest && find -type f | sed 's/\.[^.]*$//' | sort)
comm -3 <(cd source && for x in *; do printf '%s\n' "${x%.*}"; done | sort) \
        <(cd dest && for x in *; do printf '%s\n' "${x%.*}"; done | sort)

Shorter, in zsh:

comm -3 <(cd source && print -lr **/*(:r)) <(cd dest && print -lr **/*(:r))
comm -3 <(print -lr source/*(:t:r)) <(print -lr dest/*(:t:r))

The comm command details the lines that prevail to 2 files (comm -12), that are just in the first documents (comm -23) or that are just in the 2nd documents (comm -13). The numbers show what is deducted from the result ¹. Both input files have to be arranged.

Below, the files remain in reality the result of a command. The covering reviews the <(…) construct by giving a "phony" documents (a FIFO or a /dev/fd/ called documents descriptor) as the argument to the command.

¹ So below the minus sayers are totally warranted.

If you intend to execute activities on the files, you'll possibly intend to iterate over the resource files.

cd source
for x in *; do
  set -- "…/dest/${x%.*}".*
  if [ $# -eq 1 ] && ! [ -e "$1" ]; then
    echo "$x has not been converted"
  elif [ $# -gt 1 ]; then
    echo "$x has been converted to more than one output file: " "[email protected]"
    echo "$x has been converted to $1"
2019-05-17 20:06:25