0

I have two folders Folder A - Has a total of 1786 dm4 files Folder B - Has total of 2131 tbz(archive file of the dm4s available in both A and B folder) files along with 124 dm4 files which are not in Folder A.

Goal is to have all the dm4s in one folder and make sure none of the dm4s is missing which have tbz file in folder B. However when I copy all the missing 124 dm4 files from Folder B to A, it adds unto 1910 DM4 files. However, my folder B shows that I have 2131 tbz. That means I need to know the names of the remaining 221 dm4 files/tbz files which are present in folder b, so I know that they are missing from my list of dm4s.

What is the quickest way to find which dm4s/tbz file I am missing in this instance.

0

To make sure I understand, is this correct?

You have 2131 .tbz files, and each should have a corresponding .dm4 i.e. example-file-09.tbz example-file-09.dm4 But you're missing a number of the corresponding dm4 files, and need to find which they are.

Assuming that's correct, this should work (assuming you don't have any whitespace in your filenames)

dm4_files="$(find A -name '*.dm4')"
for file in $(find B -name '*.tbz'); do 
  # || is a logical or operator; bash will only execute the right side if the left side fails (returns a non-zero exit code)
  echo -e "$dm4_files" | grep -q "$(basename $file .tbz).dm4" || echo "Missing $(basename $file .tbz).dm4"
done

edit: adding instructions for running due to poor comment formatting

To run from a terminal:

  1. Change A and B above to the full paths to the directories in question (alternatively, cd to the directory containing both)
  2. Paste in the commands

To run from a script:

  1. Put the commands in a file named something like check-dm4.sh in the directory with A and B (the .sh suffix doesn't do anything, but is conventional for shell scripts)
  2. Insert the following line at the top of the file (first line) #!/bin/bash
  3. Mark the file as executable (chmod +x check-dm4.sh, or with right-click->properties/whatever your distro calls it) 4. Run the file
  • Riordan, you got that right. Now how do I run such commands. I have never created a shell script and usually run commands seperately. You think if I run above commands separately, they will work, or can you tell me a quick way to save it as a scrip and then run this file. – mywayz Jun 5 at 18:17
  • To run from a terminal: 1. Change A and B above to the full paths to the directories in question (alternatively, cd to the directory containing both) 2. Paste in the commands To run from a script: 1. Put the commands in a file named something like check-dm4.sh in the directory with A and B (the .sh suffix doesn't do anything, but is conventional for shell scripts) 2. Insert the following to the top of the file (first line) #!/bin/bash 3. Mark the file as executable (chmod +x check-dm4.sh, or with right-click->properties/whatever your distro calls it) 4. Run the file – Riordan Hanly Jun 5 at 20:12
  • My apologies for the formatting there. I didn't realize it would eat the newlines. – Riordan Hanly Jun 5 at 20:20
  • Thanks Riordan, I will try this. Appreciate the help. – mywayz Jun 6 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.