Compare files with different names in different directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare files with different names in different directories
# 1  
Old 04-03-2015
Compare files with different names in different directories

Hi,

I have a requirement to compare files in different directories with different names. The files have a datestamp in their name (It might not be a sequential datetimestamp).
This is for Redhat Linux. I have more than 5 directories and more than 10 file in each directory to be compared.

Code:
/Directory1
       f1.txt.04012015
       f2.txt.04012015
       f3.txt.04012015
/Directory2
       f1.txt.04022015
       f2.txt.04022015
       f3.txt.04022015
/Directory3
       f1.txt.04032015
       f2.txt.04032015
       f3.txt.04032015

So far I have written a shell script to do this in a very simple manner - But i think there has to be a better way

diff Directory1/f1.txt.04012015 Directory2/f1.txt.04022015
diff Directory1/f2.txt.04012015 Directory2/f2.txt.04022015
...
..


Last edited by GosarJunk; 04-03-2015 at 07:38 PM.. Reason: adding code tags
# 2  
Old 04-03-2015
We could make lots of assumptions about whether or not the names of the files in your various directories are all the same, what is supposed to happen if some files don't appear in some directories but do appear in others, what shell you're using, how you want the output presented, etc.

Why don't you show us the script you have now, and tell us what needs to be changed to get what you want out of it?
# 3  
Old 04-04-2015
Hi.

See find same size file for a demonstration of utilities fdupes and rdfind

Best wishes ... cheers, drl

https://www.unix.com/man-page/debian/1/fdupes/

https://www.unix.com/man-page/debian/1/rdfind/
# 4  
Old 04-20-2015
Sorry for the late reply

Don,

Names of the files in various directories will be same except for the datetime appended at the end of the files. All the files will appear in all the directories. I can use the BASH shell or the basic shell or KSH. I am just trying to get a "Diff" from the similar files in different directories. Output will be similar to the "diff" command. The script i have curently is as shown in my original post - List of "diff" commands will actual files-names for all the files.
Code:
/usr/bin/diff Directory1/f1.txt.04012015 Directory2/f1.txt.04022015 
/usr/bin/diff Directory1/f2.txt.04012015 Directory2/f2.txt.04022015
...
...

# 5  
Old 04-20-2015
Quote:
Originally Posted by GosarJunk
Sorry for the late reply

Don,

Names of the files in various directories will be same except for the datetime appended at the end of the files. All the files will appear in all the directories. I can use the BASH shell or the basic shell or KSH. I am just trying to get a "Diff" from the similar files in different directories. Output will be similar to the "diff" command. The script i have curently is as shown in my original post - List of "diff" commands will actual files-names for all the files.
Code:
/usr/bin/diff Directory1/f1.txt.04012015 Directory2/f1.txt.04022015 
/usr/bin/diff Directory1/f2.txt.04012015 Directory2/f2.txt.04022015
...
...

In your first post in this thread, you said you had a shell script that produced a script of the diff commands you wanted to execute, and you showed us the 1st two lines of output from that script.

Show us that script; not its output! It will help us understand what your directory structure really looks like, what files need to be compared, what you want done if expected files are missing, ... ... ... Without seeing your working script, there are just too many details that you haven't specified to be able to be of much help; unless you just want us to waste our time trying to guess at your requirements.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two files containing package names and version number

I have 2 files each containing a list of same fedora packages but with different version number. I want to compare the 2 files and remove the lines containing a newer or older version number (1 Reply)
Discussion started by: asya18
1 Replies

2. Shell Programming and Scripting

Compare two files and get only missing names

I need to compare two files (oldfile1 & newfile). Need to ignore the values which are present in both files. At the same time, i need to get only records in new file. Tried using Join -v1 -v2 oldfile1 newfile (suspect it has not worked as expected). could anyone of you please help me here. (5 Replies)
Discussion started by: Selva_2507
5 Replies

3. UNIX for Dummies Questions & Answers

Compare files in two directories

Hi All, I have two directories that has some files, some of the files are common to both of them like : ls -l dir1 file1 file2 file3 ls -l dir2 file1 file2 file3 file4 file5 Now i want to get the files from dir2 that are not present in dir1 (means i want to get... (2 Replies)
Discussion started by: mukulverma2408
2 Replies

4. Shell Programming and Scripting

how to compare two files in different directories

Hi all , Can any one give me the solution for below query. I have two files . firstfile: xyz123 abc234 text2456 secondfile (\home\test) xyz123:ram ab34:scrit text2456:maven After you compare the ouput should the the common items in both files (2 Replies)
Discussion started by: sravan008
2 Replies

5. Shell Programming and Scripting

Extract function names and directories from php files

I need a script that extracts function names from php files together with their location (path and file in which they are defined). The php files are located in several directories under a base directory. Ideally the output should be something like: "Path/FileName/FunctionName" for a... (2 Replies)
Discussion started by: bamse
2 Replies

6. Shell Programming and Scripting

Check for particular files and compare the file names

Hi, Below are the 2 files in directory /tmp: masterCSF242323.img indexCSF242323.img 1) I want to compare if both the number (242323) are same in both the files. If they are same print - Files matching, else print files do not match. 2) Also if only index file is present in that... (7 Replies)
Discussion started by: apatil65
7 Replies

7. UNIX for Dummies Questions & Answers

how to compare names of files?

hi, can somebody tell me how to compare names of files? the situation is I have 2 files file1 and file2 and I want to figure out which file has the biggest ending, in this case file2 is. thank you (3 Replies)
Discussion started by: s3270226
3 Replies

8. Shell Programming and Scripting

Compare list [ names and size files ]

Hello, I've downloaded a huge amont of files I've got a list of files from a remote server. -rw-r--r-- 1 str661 strem 453465260 Dec 16 15:54 SATRYS2V1_20021218_temp_bias.nc -rw-r--r-- 1 str661 strem 17669468 Dec 16 18:01 SATRYS2V1_20021225_hdyn_bias.nc -rw-r--r-- 1... (9 Replies)
Discussion started by: Aswex
9 Replies

9. 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

10. Shell Programming and Scripting

Compare File Names in Different Directories...

I do not know much about shell scripting and need to create a script and I am at a loss. If someone can help me, that would be great!! I have two directories: /dir1 /dir2 I need to get the sequence number which is part of the filename in /dir1 and delete all files in /dir2 that are... (4 Replies)
Discussion started by: stky13
4 Replies
Login or Register to Ask a Question