LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-09-2005, 06:52 AM   #1
Prasun1
Member
 
Registered: Jun 2005
Posts: 41

Rep: Reputation: 15
reqd to find the difference between two files


Hi,

This is something which I have been trying to solve. Basically I have some files in my LInux box (in different directories) that have the same name but with different contents.

I want to write a shell script that will compare between a given pair of such files and write in a report file if at all the files are similar or different.

As an input the program takes a filename each time it is run and then compares it in different directories to produce the result. Next time when the script is again executed it takes as an input another filename and produces the difference report between these two files.

Any help regarding this will be highly appreciated.

Thanks and Regards
Prasun
 
Old 09-09-2005, 08:44 AM   #2
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
You can use diff to compare files (type man diff for more information).
 
Old 09-09-2005, 11:27 AM   #3
Prasun1
Member
 
Registered: Jun 2005
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks a lot but I was really looking for a script.

Regards
Prasun
 
Old 09-09-2005, 11:34 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Code:
#!/bin/bash
echo "Enter the filename for comparison:"
read FNAME

diff -u dir1/$FNAME dir2/$FNAME
 
Old 09-09-2005, 02:49 PM   #5
Prasun1
Member
 
Registered: Jun 2005
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks a lot , I was looking at something like this only , but I still have a question i.e say for eg there's difference in the content of the two files i.e file1 and file2 . How do I then go n report in the report file that "there is a difference" .I mean I could not construct the if ........ statment here.It will be driven by this logic if [there's a difference ]
then
echo "message" .....


Please help me to write this code

Thanks and Regards
Prasun
 
Old 09-09-2005, 03:14 PM   #6
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
diff returns 0 if the files are equal, and 1 if they are not.
 
Old 09-09-2005, 03:49 PM   #7
JCipriani
Member
 
Registered: Aug 2005
Location: Pittsburgh, PA, USA
Distribution: Redhat 9, OS X 10.4.x, Win2K
Posts: 85

Rep: Reputation: 15
If you're more of a minimalist, there is also cmp, which won't find all the actual differences as intelligently diff will but will tell you if the files are different or not. See the cmp man page; it's return values are documented. See the sh/csh/whatever man pages for info about how the scripts actually work and how to evaluate the return value of a command and construct if statements and stuff.
 
Old 09-09-2005, 05:16 PM   #8
Prasun1
Member
 
Registered: Jun 2005
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks a lot , I think now I can independently design the script

Regards
Prasun
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is routed really reqd ?? jkmartha Linux - Networking 1 04-30-2005 03:39 AM
How can i find the difference for directory alice95089 Linux - Software 4 02-07-2005 08:49 AM
.rar files versus .iso files the difference? dolphans1 Mandriva 14 01-31-2005 09:33 AM
my way of booting some suggestions /comments reqd ninadb Linux - General 3 07-18-2004 02:35 AM
MAKE help reqd please brookes Mandriva 1 10-26-2003 01:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration