Compare two folders and file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two folders and file content
# 15  
Old 10-17-2014
It does show the entire difference. If it's not what you want, please show what it does, then show what you'd rather have it do.
# 16  
Old 10-17-2014
Hi,

Yeah its worked but is there a way to redirect the output to respective log file

Code:
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

Code:
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

# 17  
Old 10-17-2014
So f1.log isn't the file being checked, it's the file data is printed to?

Does it belong in the first or second dir, or elsewhere?
# 18  
Old 10-17-2014
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"
# 19  
Old 10-17-2014
Quote:
Originally Posted by rohit_shinez
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.
But what if there's two different files of the same name? like dir1/a/f1 and dir1/b/f1
# 20  
Old 10-17-2014
In that case print the output in same f1.log with which directory the diff is there
# 21  
Old 10-20-2014
Is this anything close to what you want?
Code:
log0=/tmp/changes.log

diff -r <(ls -1 $1 | sort)  <(ls -1 $2 | sort) > /tmp/junk0

if [ ! -z /tmp/junk0 ]; then
    >$log0
    printf "Dirs %s and %s differ\n" $1 $2 > $log0
    echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $log0

    while read buf
    do
        if [[ ${buf:0:1} == '<' ]]; then
            printf "%s.log: File added: %s\n" $1 ${buf##*<} >> $log0
        elif [[ ${buf:0:1} == '>' ]]; then
            printf "%s.log: File added: %s\n" $2 ${buf##*>} >> $log0
        fi
    done < /tmp/junk0
fi

cat $log0
# rm  /tmp/junk0 $log0


Last edited by ongoto; 10-20-2014 at 12:16 PM.. Reason: forgot >> $log0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to compare files in 2 folders and delete the large file

Hello, my first thread here. I've been searching and fiddling around for about a week and I cannot find a solution.:confused: I have been converting all of my home videos to HEVC and sometimes the files end up smaller and sometimes they don't. I am currently comparing all the video files... (5 Replies)
Discussion started by: Josh52180
5 Replies

2. Shell Programming and Scripting

Compare & print content of file which is not matching

Hi All I want to compare 2 files using awk and get output of content which is not matching I have 2 files a.txt 123 456 780 143 b.txt A|B|C|167|D|E C|K|D|123|D|E A|B|D|789|G|F C|D|G|143|A|B Not matching line from b.txt O/P A|B|C|167|D|E A|B|D|789|G|F (3 Replies)
Discussion started by: aaysa123
3 Replies

3. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

4. Shell Programming and Scripting

Ksh: how compare content of a file with an other array

Hi, I created a skript in ksh which generate a file with semicolon as separator, this is an example of the file a created: example content file: hello;AAAA;2014-08-17 hello;BBBB;2014-08-17 hello;CCCC;2014-08-17 I would need to compare the content in of the second column of this file... (3 Replies)
Discussion started by: jmartin
3 Replies

5. Shell Programming and Scripting

Bash selective copy folders and content to another location

I'm looking for a bash scrypt to copy some folders and some of the content to another location. I'm a teacher and very noobish with programming language anyway what I'm looking for , I have this director structure Main director "Students" with subfolders "john";"daisy";"work" etc .. and some of... (2 Replies)
Discussion started by: brickleul
2 Replies

6. Shell Programming and Scripting

split file content into specific folders

Hi I have a large text file and I want to split its content into multiple flies. this large file contains several blocks of codes separated by a comment line for each block. this comment line represents a directory path So, when separate these blocks each into a separate file, This output... (7 Replies)
Discussion started by: turki_00
7 Replies

7. Shell Programming and Scripting

Compare 2 folders...

Hello, I try to compare 2 folders, i explain, i have file in this 2 folder and i want to print out the difference in this folders... ex: folder1: file1 file2 file3 folder2: file1 file2 print file3 I do a ls of the 2 folders and i use the command diff (diff $var1 $var2) without... (8 Replies)
Discussion started by: protocomm
8 Replies

8. UNIX for Dummies Questions & Answers

To compare selective file in different folders

Hello, I am using dircmp -d <folde1> <Folder2> to compare the files from two different foldes, but this command compares for all the files. Is there any option to select only some files for comparision. For example in Folder1: file1.txt file2.txt file3.txt Folder2 file1.txt file2.txt... (0 Replies)
Discussion started by: gmahesh2k
0 Replies

9. Shell Programming and Scripting

To Compare content of one file with other file

Hi All, I need to compare the content of one file with the other.The first file holds the records: aaa ,123 bbb,321 ccc,890 Second file willl holds the record aaa,bbb,ccc My problem is i need to take the first column of file one and compare with the first row of second file.If it... (1 Reply)
Discussion started by: ithirak17
1 Replies

10. Shell Programming and Scripting

Remote compare of folders

Hi, Is there a way (either commands/tools/scripts/logic) to compare two given folders on different unix boxes. I want to compare folder a in Unix box 'A' with folder 'b' in Unix box 'B'. I can run the script in Unix box 'A'. I am looking. for following results: files/sub folders only in a... (1 Reply)
Discussion started by: sunilav
1 Replies
Login or Register to Ask a Question