for file in A/*.txt_*; do
newfile="B/${file##*/}" # remove A path, add B path
newfile="${newfile%_*}" # remove trailing suffix
if [[ ! -f "$newfile" ]]; then
mv "$file" "$newfile"
fi
done
Isso iterará todos os arquivos em A que corresponderem a *.txt_* . Ele construirá um novo caminho de arquivo substituindo o caminho A pelo caminho B e retirando o sufixo _xxxxxxxx do nome do arquivo. Se o novo nome do arquivo não estiver presente em B , o arquivo será movido para lá.