Looking to find files that are similar.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looking to find files that are similar.
# 1  
Old 10-01-2012
Looking to find files that are similar.

Hello all,

I have a server that is running AIX, running a tool that converts various printstreams (AFP/Metadata) to PDF. This is done using a rexx script and an off the shelf utility.

Each report (there's around 125) uses a certain script file, it's basically a text file.

I am trying to find out if the scripts are similar, some of them might even be the same, and I'm wondering if anyone has any advice on the best way to do this.

Here is a sample of what it would be like:

1 or multiple script files (.txt) might be in:
Code:
/app/transformation/project1/

Other files exist...etc..

Code:
/app/transformation/project2/

Does anyone have feedback on what the best way to compare?
# 2  
Old 10-01-2012
Code:
diff -lrs /app/transformation/project1/ /app/transformation/project2/ | more

# 3  
Old 10-01-2012
Thank you for the prompt response. This method looks like it will work, but I am wondering if there is any way to compare more than 2 files.
# 4  
Old 10-01-2012
define compare. How similar are we talking here? Exactly the same means they are similar? If so use checksums.
Code:
for file in /app/transformation/project1/*.pdf /app/transformation/project2/*.pdf
do
  cksum $file
done  | sort -n   > my pdfs.txt

matching files will all have the same checksum. AIX cksum example output:
Code:
3995432187       1390    file.pdf

where 3995432187 is the checksum, 1390 is the file size in bytes, file1.pdf is the filename. This is why sorting by checksum finds multiple duplicates.
# 5  
Old 10-01-2012
Quote:
Originally Posted by jim mcnamara
define compare. How similar are we talking here? Exactly the same means they are similar? If so use checksums.
Code:
for file in /app/transformation/project1/*.pdf /app/transformation/project2/*.pdf
do
  cksum $file
done  | sort -n   > my pdfs.txt

matching files will all have the same checksum. AIX cksum example output:
Code:
3995432187       1390    file.pdf

where 3995432187 is the checksum, 1390 is the file size in bytes, file1.pdf is the filename. This is why sorting by checksum finds multiple duplicates.
Just wanted to point out a gotcha here: even a single extra blank line or a space will produce dissimilar cksums. Otherwise this is okay to find similar files.
# 6  
Old 10-01-2012
identical=exact which should mean the checksums match. Similarity is a really difficult problem - google for Levenshtein distance or Wagner-Fischer algorithm.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Similar Threads: More UNIX and Linux Forum Topics You Might Find Helpful Update

Today I change the DB and the PHP code and rebuilt the database for similar threads at the end of each post, increasing from a max of 5 to a max of 10 similar threads per post: More UNIX and Linux Forum Topics You Might Find Helpful It was quite easy to do: 1. Increased the max size of... (17 Replies)
Discussion started by: Neo
17 Replies

2. Solaris

Getting similar lines in two files

Hi, I need to compare the /etc/passwd files from 2 servers, and extract the users that are similar in these two files. I sorted the 2 files based on the user IDs (UID) (3rd column). I first sorted the files using the username (1st column), however when I use comm to compare the files there is no... (1 Reply)
Discussion started by: anaigini45
1 Replies

3. Shell Programming and Scripting

To find ls of similar pattern files in a directory by passing the variable.

Hi, I have file in my $datadir as below :- SAT_1.txt SAT_2.txt BAT_UD.lst BAT_DD1.lst DUTT_1.txt DUTT_la.txt Expected result :- should get all the above file in $<Filename>_file.lst Below is my code :- for i in SAT BAT DUTT do touch a.lst cd $datadir (1 Reply)
Discussion started by: satishmallidi
1 Replies

4. UNIX for Dummies Questions & Answers

To find similar items in a column

HI, I have a long file which looks like "1xxx_0_1" "1xxx" 500 5 "ABC*3-DEF*3-LL" "2yyy_0_1" "2yyy" 600 10 "ABC*2-DEF*2-LL" "3ddd_0_1" "3ddd" 150 52 "ABC*3-DEF*3-LL" "1xxx_0_1" "1xxx" 500 5 "ABC*3-DEF*3-LL" "2yyy_0_1" "2yyy" 600 10 "ABC*2-DEF*2-LL" ... (3 Replies)
Discussion started by: XXLMMN
3 Replies

5. UNIX for Dummies Questions & Answers

Find the average based on similar names in the first column

I have a table, say this: name1 num1 num2 num3 num4 name2 num5 num6 num7 num8 name3 num1 num3 num4 num9 name2 num8 num9 num1 num2 name2 num4 num5 num6 num4 name4 num4 num5 num7 num8 name5 num1 num3 num9 num7 name5 num6 num8 num3 num4 I want a code that will sort my data according... (4 Replies)
Discussion started by: FelipeAd
4 Replies

6. Shell Programming and Scripting

How to find similar values in different files

Hello, I have 4 files like this: file1: cg24163616 15 297 cg09335911 123 297 cg13515808 565 776 cg12242345 499 705 cg22905282 225 427 cg16674860 286 779 cg14251734 303 724 cg19316579 211 717 cg00612625 422 643 file2:... (2 Replies)
Discussion started by: linseyr
2 Replies

7. Shell Programming and Scripting

Find the similar directory

Hi I have one directory whose name i don't remember exactly only starting letter i know which is Resp. Can you please let me know the command to find the similar directory in the root. Rajesh (3 Replies)
Discussion started by: guddu_12
3 Replies

8. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

9. Shell Programming and Scripting

Find similar entry in a .txt file acting as a database.

May i know how do i go along finding similar entry in a .txt file, which is used a as a "database" and post and error saying the entry existed when we key in the entry. ---------- Post updated at 05:18 PM ---------- Previous update was at 05:16 PM ---------- i mean post an error saying the... (5 Replies)
Discussion started by: santonio
5 Replies

10. Shell Programming and Scripting

compare the similar files

I got many pair files, which only have small difference, such as more space, or more empty line, and some unreadable characters. If list by commend "diff", I can see many many difference. So I'd like to write a script to compare the pair files, if 95% contents are same, I will think they are... (2 Replies)
Discussion started by: rdcwayx
2 Replies
Login or Register to Ask a Question