compare 2 filenames & move one to other's directory
by ericlindellnyc from LinuxQuestions.org on (#4TMH2)
I have code that compares two files, & if equal, touches one with the other, so it has the same date.
This time, I'd like to compare the file names only, without the extension, and if equal, move one to the other's subdirectory.
This process makes the comparison for all files in two directories, iterating through one directory to find a match for each in the other directory, which it also iterates through, for a nested loop.
FILES=$( find ./nu/Mrj -type f ); for f in $FILES; do for g in ./ol/Mrj/*; do echo "f is $f g is $g"; if cmp "$f" "$g"; then echo "match"; touch -r $g $f; else echo "no match"; fi; done; done
Thanks in advance


This time, I'd like to compare the file names only, without the extension, and if equal, move one to the other's subdirectory.
This process makes the comparison for all files in two directories, iterating through one directory to find a match for each in the other directory, which it also iterates through, for a nested loop.
FILES=$( find ./nu/Mrj -type f ); for f in $FILES; do for g in ./ol/Mrj/*; do echo "f is $f g is $g"; if cmp "$f" "$g"; then echo "match"; touch -r $g $f; else echo "no match"; fi; done; done
Thanks in advance