LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-16-2009, 07:38 AM   #1
fpp666
LQ Newbie
 
Registered: Jul 2009
Posts: 10

Rep: Reputation: 0
How can I print a message when a diff shows files match?


Hello all!

I'm writing a script using ksh that diffs two dirs that contain about 30 files, and writing the results on a logfile.

When files differ, it writes the difference with no problem, but I also need the script to write a message if no differences are found.

Thanks for the help!
 
Old 07-16-2009, 07:42 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
How are you taking the difference of the file please post the code snippet?? are you using diff -r to do so or you are comparing it one by one?
 
Old 07-16-2009, 07:57 AM   #3
fpp666
LQ Newbie
 
Registered: Jul 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Sorry I didn't post the code. It's a simple diff between two dirs, using a FOR sentence, because only the files that start with VFR in the first dir (dir_old) are on the second one (dir_firstSet)

Code:
cd $dir_old
echo 'first set comparison ###############################' >> logfile

for name in VFR*
	do
		echo "$dir_old$name" >> logfile
		diff "$name" "$dir_firstSet$name" >> logfile
	done
Thanks!
 
Old 07-16-2009, 08:19 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
cd $dir_old
echo 'first set comparison ###############################' >> logfile

for name in VFR*
	do
		echo "$dir_old$name" >> logfile
		difference=`diff "$name" "$dir_firstSet$name"`
                if [ $difference ]
                then
                    echo $difference >> logfile
                else
                    echo "No difference in $name $dir_firstSet$name" >> logfile
                fi
	done

Last edited by PMP; 07-16-2009 at 08:27 AM.
 
  


Reply

Tags
diff, scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use diff to only print lines fancylad Linux - General 10 06-17-2013 12:50 PM
CUPS - Print jobs shows completed, but page doesn't print hikerguy Linux - Software 8 12-17-2008 01:55 AM
mp3 player looses capacity - 2gb -. 1.3gb (du / df commands shows diff capacities) colinkingswood Linux - Hardware 2 10-06-2008 10:10 AM
Using diff and erasing the lines that match ElectroLinux Linux - Newbie 4 09-20-2006 03:34 AM
compare two files in C and print the line when they do not match calorie712 Programming 7 04-13-2006 01:56 AM


All times are GMT -5. The time now is 01:52 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration