I am having two folders where i need to compare the content of files and also to know if any new files been added and redirect the difference output in respective filename logs. For e.g.:
Directory D1:
f1
f2
f3
Directory D2:
f1
f2
f3
f4
i Need to compare the directories D1 and D2 and write it respective file log of there are any difference and if any additional file added write in another log file
Output content in the log file
f1.log - There is a difference in the f1 and f2, please find the below difference:
......
f2.log - No difference found
f3.log - No difference found
Additional.log - There is additional file in D2 with filename as f4
I am able to get only the outputs as showing there is file difference and additional file present in D2 i need to print the difference like how it can be achieved in respective log
You are creating log files in the same directory that you are comparing.
Redirect to another path so the log files are not included as part of the `diff'
Yeah its worked but is there a way to redirect the output to respective log file
f1.log - There is a difference in the f1 and f2, please find the below difference:
......
f2.log - No difference found
f3.log - No difference found
Additional.log - There is additional file in D2 with filename as f4
diff -rs a b |
awk -F"[: \t]" '
/^diff/ { print "difference between " $3, $4 ; getline ; getline
while(/^[<>-]/) { print ; if(getline != 1) break } }
/^Only in/ { print "There is additional file in "$3" with filename as "$NF }
/identical$/ { N=split($2, A, "/"); print A[N] " - no difference found" }' >$3.log
This will be redirected to somewhere else for e.g. like to check the log of difference between two directories and print the desired output in respective file logs.
If f1 from D1 and f1 D2 are identical print the output in f1.log as "No difference found"
If difference found f1.log should have output as "Please find the difference below:
show the difference
"
If there is an additional file then print the output log as additional.log as "Please find the additional file below:
There is additional file in D2 with filename as f4"