I am writing a script where I need to compare 2 directories (recursively) and write out only files if they have different size or time of modify(YY-MM-DD HH:MM) or if file exists only in one directory.
Output be in format:
<dir1>:<local-path> <size> <last-modify> <dir2>:<local-path> <size> <last-modify>
If file exists only in one directory:
<dir1>:<local-path> <size> <last-modify>
or
<dir2>:<local-path> <size> <last-modify>
So far I managed to get my data in specified format using:
find dir1 -type f -exec stat -c '%n %s %y' {} \; | sed 's,^[^/]*/,,' | sed 's/\:[^:]*$//' | sort # > dir1.txt
find dir2 -type f -exec stat -c '%n %s %y' {} \; | sed 's,^[^/]*/,,' | sed 's/\:[^:]*$//' | sort # > dir2.txt
Which gives me 2 ordered lists of files in given directories and subdirectories and their size and last modified timestamp.
Now I need to somehow compare them and get them to specified format above. I tried using diff -y but it compares line by line but I need same name to same name. I also tried comm but dont know how to transform that output format.
Any ideas?