A hacky solution using
$ mkdir folderA folderB folderC
$ touch folderA/fi\ le1 folderA/file2 folderA/file3 folderB/file3 folderB/file4
$ diff -rq folderA folderB
Only in folderA: fi le1
Only in folderA: file2
Only in folderB: file4
Now we use
sed to filter all lines starting with string
Only in folderA: and we change this part to
folderA/ to form a
relative filename with quotes (
'folderA/fi le1'). This string is then piped to
xargs and used to copy this file to
$ diff -rq folderA folderB | sed -n "s/^Only in \(folderA\): \(.*\)/'\1\/\2'/p" | xargs cp -vt folderC
'folderA/fi le1' -> 'folderC/fi le1'
'folderA/file2' -> 'folderC/file2'
The same as above for
$ diff -rq folderA folderB | sed -n "s/^Only in \(folderB\): \(.*\)/'\1\/\2'/p" | xargs cp -vt folderC
'folderB/file4' -> 'folderC/file4'