I want to write a script that compares two directories.
However, the file names are modified in one of them.
So directory A contains files like HouseFile.txt, CouchFile.txt, ChairFile.txt
Directory B contains House.txt, Couch.txt, Chair.txt (which should be seen as ‘equivalent’ to the above)
Both may also contain new, completely different files.
Could someone point me in the right direction here? It’s been a while since I’ve done scripting.
I have tried using diff, and I know I need to use some form of regexto compare the file names, but I am not sure where to start.
Thank you!
Added for clarification:
Of course diff, however, just compares the actual file names. I would like to know how to specify that I regard files names such as, in the example, “HouseFile.txt” and “House.txt” as equivalent in this case
If I understand correctly, this is a possible solution to compare a to b:
mkdir a b ; touch a/HouseFile.txt a/ChairFile.txt a/CouchFile.txt a/SomeFile.txt b/House.txt b/Chair.txt b/Couch.txt b/Sofa.txtfor file in a/*(.); do [[ ! -f b/${${file##*/}:fs@File@} ]] && echo $file ; doneOutputs:
a/SomeFile.txtWhat is not clear to me: Is the difference pattern strictly ‘File’ or any arbitrary string?
EDIT: The previous was for zsh. Here is one for bash:
Using parameter expansion instead of
sed: