Compare files across 2 UNIX boxes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare files across 2 UNIX boxes
# 1  
Old 09-27-2006
Compare files across 2 UNIX boxes

Is it possible to compare two files which reside on different UNIX boxes?
(I'm using HP POSIX/Korn) Smilie

Consider the scenario of a pre-production environment (box 1) and a production environment (box 2) I would like to check if some files on both boxes match or not.

It's quite straightforward on one box:

#----------------------------------------------------
# Function to compares files and display differences
#
# $1 = file1, $2 = file2
#
# cmp with option -s gives the following return codes:
# 0 - identical
# 1 - different
# 2 - inaccessable/other
#----------------------------------------------------
function fn030_compare_file {

cmp -s $1 $2

if [[ $? -gt 0 ]]
then
echo "*** Difference in files! -----> $1 <---> $2"
else
echo "*** OK, Files identical -----> $1 <---> $2"
fi

return
}

The only alternative I can think of is to copy the files to one box, then compare from there.

NOTE: I found an excellent shell script which recursively compares the contents of two directories on one box (to find this do a google search on "cmptree"...)
# 2  
Old 09-27-2006
You do realize there's already a perfectly good program to compare files without you building your own, right? It's called 'diff'.

As for comparing files on different systems, you could mount a directory from one machine onto another with nfs.
# 3  
Old 09-27-2006
Basicly you need to get the remote file back to your local system to be able "diff" the two. Mount via nfs, or try a "rcp" to get a copy...

Can't think of a way you can use "diff" on two files where one is local and the other is remote?
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 in UNIX

I have requirement to compare two files in unix. Below are the sample files. File1: cn=test123,cn=bobgroup,dc=ind,dc=com cn=bob123,cn=bobgroup,dc=ind,dc=com cn=test13,cn=bobgroup,dc=ind,dc=com cn=est12,cn=bobgroup,dc=ind,dc=com cn=st123,cn=bobgroup,dc=ind,dc=com File2... (1 Reply)
Discussion started by: babu92
1 Replies

2. Shell Programming and Scripting

Compare two files in UNIX

Hi, I have two files File1 Contents: abc dcf sdc File2 Contents: dcf sdc erg Now my program should return the contents existing in File1 but not in File2. In this case output shoud be "abc" as abc is not available in File 2. It should not return "erg" by saying it is... (4 Replies)
Discussion started by: forums123456
4 Replies

3. Shell Programming and Scripting

Compare two files in unix

Hi Gurus I need your kind help sorting the below query I have two text files File1.txt ID Name Address 101 Srinath BBB 102 Sidharth CCC File2.txt ID Name Address 102 Siddharth DDD 103 Suman EEE Now the requirement is if the second file has... (0 Replies)
Discussion started by: Pratik4891
0 Replies

4. UNIX for Dummies Questions & Answers

problem to determine all files and dir match up on 2 different unix boxes

Hi Friends I have 2 solaris boxes and I need to check certain directories (on local filesystem and mounted nfs) to make sure that they match up on both boxes and to delete or move the other mismatches to elsewhere on the local filesystem. I investigated for unix commands like rsync, and tree... (1 Reply)
Discussion started by: mpc8250
1 Replies

5. UNIX for Advanced & Expert Users

How to compare two files using UNIX?

I have two files which have primary key(s) for each row. I need to compare both the files and produce the output in the following format. Primary key(s),file1 value,file2 value. Both the input files will be comma separated files. I have accomplished this using perl, but it is... (6 Replies)
Discussion started by: gpsridhar
6 Replies

6. UNIX for Dummies Questions & Answers

how can i unix compare two files??

how can i unix compare two files?? var1 = 6499 7328 6351 7583 7573 var2 = 6499 7328 6351 7583 7777 i did: diff $var1 $var2 and i got the output: 1c1 < 6499 7328 6351 7583 7573 --- > 6499 7328 6351 7583 7777 what can i do with it? and what does it tell me?? how can i knoe that... (2 Replies)
Discussion started by: nirnir26
2 Replies

7. UNIX for Dummies Questions & Answers

Unix Compare Files

Hi, I need to compare 2 files based on the first field in each file and output the differences to a new file. example File 1 and File 2 both have first field as Number ie: File 1 1252652355 1859553322 1778899562 File 2 1252652355 1859553322 So I would expect File 3 to... (2 Replies)
Discussion started by: Lagre1
2 Replies

8. UNIX for Advanced & Expert Users

UNIX; Compare two files

Hi Guys, Requirement: Want to compare two files, if the the content of both files is same then show "Good result" else Show "Bad Result" I am using the following logic if( cmp -s a b = 0 ) then echo "Good result" else echo "Bad result" exit 0 fi But this is... (1 Reply)
Discussion started by: abhishek3598
1 Replies

9. UNIX for Dummies Questions & Answers

Help! Suggestions on what I can I use my 2 unix boxes for?

Once upon a looong time ago I used to work with Unix systems - SGI mainly. Now I've inherited 2 boxes - an SGI dual processor Octane and an Indigo2. For the past 2 years they've sat waiting for me to do something with them and never getting round to it. I run a windows network at home so... (3 Replies)
Discussion started by: JimmyChang
3 Replies

10. Programming

text boxes, radio buttons , check boxes in c++ on unix

Hi ! Please tell me how to get radio buttons, text boxes , check boxes , option buttons , pull down menus in C++ on Unix. I think it would be done using curses.h ..but that's all i know. TIA, Devyani. (3 Replies)
Discussion started by: devy8
3 Replies
Login or Register to Ask a Question