Compare files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare files in a directory
# 1  
Old 02-11-2011
Compare files in a directory

Hi friends, can anyone help me comparing files in a directory. I have files f1, f2, f3, f4, f5, f6, f7, f8 in a directory each created on a daily basis as f1 on day1, f2 on day2, f3 on day3, f4 on day4, f5 on day5, f6 on day6, f7 on day7, f8 on day8. I need ignore the latest two files (here f7 and f8) from comparison.
I just need to compare files f1, f2, f3, f4, f5, f6 and print the difference. Also can i compare only a set of files say f4, f5, f6 as the file count increases on a daily basis ignoring the latest two files.
Any clue or suggestions would be great.
Thanks in advance!
nmattam
# 2  
Old 02-12-2011
Code:
DIR1=/xxx
DIR2=/yyy

cd $DIR!

for file in `ls f* |sort -rn |sed '1,2d' `
do
    diff file $DIR2/$file
done

# 3  
Old 02-14-2011
Compare files in a directory

Hi rdcwayx, Just tried with the code you have given. I can get the file list excluding the latest 2 files as i expected using `ls f* |sort -rn |sed '1,2d' `
. I am not sure how the diff is done on all the rest of the files.Can you please explain? I am looking for diff of files f1 to f6, the output should be intersection of each of the file contents.
f1: a, b, c
f2: a, b, c, d
f3: a, b, c, d
f4: a, b, c, d, e
f5: a, b, c
f6: a, b, c, d, e, f
Output should result in diff of all files containing d, e, f. Thanks in advance!
# 4  
Old 02-14-2011
run the diff directly, get the output, you can understand it.

If still not:

Code:
man diff

# 5  
Old 02-14-2011
Compare files in a directory

Thanks for help rdcwayx. I find this when executing the command.

Code:
diff: file: No such file or directory
diff: avail_logs1/departed_employee_views.2011_week14: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_employee_views.2011_week13: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_employee_views.2011_week12: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_employee_views.2011_week11: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_employee_views.2011_week10: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week09: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week08: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week07: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week06: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week05: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week04: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week03: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week02: No such file or directory
diff: file: No such file or directory
diff: avail_logs1/departed_week01: No such file or directory


Last edited by Yogesh Sawant; 02-15-2011 at 07:29 AM.. Reason: added code tags
# 6  
Old 02-14-2011
Oh, my fault.

Code:
DIR1=/xxx
DIR2=/yyy

cd $DIR!

for file in `ls f* |sort -rn |sed '1,2d' `
do
    diff $file $DIR2/$file
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare directories and copy differences (files) in a another directory

Hey im working on script that can compare 2 directory and check difference, then copy difference files in third diretory. here is the story: in folder one we have 12 subfolder and in each of them near 500 images hosted. 01 02 03 04 05 06 07 08 09 10 11 12 in folder 2 we have same subfolder... (2 Replies)
Discussion started by: nimafire
2 Replies

2. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

3. Shell Programming and Scripting

Compare Only "File Names" in 2 Files with file lists having different directory structure

I have a tar arcive arch_all.tar.gz and 4 batched tar archive . These batches are supposed to have all the files form arch1.all.tar.gz arch1_batch1.tar.gz arch1_batch2.tar.gz arch1_batch3.tar.gz arch1_batch4.tar.gz my issue is that the directory structure in "arch_all.tar.gz" is... (6 Replies)
Discussion started by: sumang24
6 Replies

4. Shell Programming and Scripting

perl Compare zone files in directory with what is listed in named.conf

I would really appreciate any assistance that I can get here. I am fairly new to perl. I am trying to rewrite my shell scripts to perl. Currently I have a shell script (using sed, awk, grep, etc) that gets a list of all of the zone files in a directory and then looks in named.conf for what... (0 Replies)
Discussion started by: brianjb
0 Replies

5. Shell Programming and Scripting

Parse files in directory and compare with another file

I have two files File 1 in reading directory is of following format Read 1 A T Read 3 T C Read 5 G T Read 7 A G Read 10 A G Read 12 C G File 2 in directory contains Read 5 A G Read 6 T C Read 7 G A Read 8 G A Read 20 A T File2 contains (1 Reply)
Discussion started by: empyrean
1 Replies

6. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

7. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

8. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together. I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Discussion started by: bkeep
4 Replies

9. Shell Programming and Scripting

Compare all files in a directory to a threshold value

Hi guys, I have the following, and would like to enhance it be be able to run it in the hard coded directory and compare each file in the directory with the expectedSizeHow would I go about doing this? Thanks, Bloke #!/bin/sh ] || { echo "Usage: watchSizes 400"; exit 0 ; } #Hammer: How... (1 Reply)
Discussion started by: Bloke
1 Replies

10. Shell Programming and Scripting

Directory compare script

Hello, I am looking for a script, or pointer to an approach to creating a script, that will compare two versions of a codebase and output a third directory structure containing only the files that differ between the two. I use diff quite often, but it will only create patch files (AFAIK). Does... (3 Replies)
Discussion started by: jwilliams108
3 Replies
Login or Register to Ask a Question