Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-25-2012, 10:23 AM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 11
Rep: 
|
LINUX - How to compare the values in 2 files & exit from the script
Hi All,
I have a requirement where I need to compare 2 files & if the values in the files match, it should proceed, else exit the script without proceeding further.
For e.g : Scenario 1
Quote:
cat File A
20120701,20120702,20120703
cat File B
20120701,20120702
|
In this case, the script should exit without proceeding further.
Scenario 2
Quote:
cat File A
20120701,20120702,20120703
cat File B
20120701,20120702,20120703
|
In this case, the script should proceed further.
Scenario 3
Quote:
cat File A
20120701,20120702,20120703
cat File B
20120701,20120702,20120704
|
In this case, the script should exit.
Can anybody shed some light on how to accomplish this.
Thanks Much
Freddie
|
|
|
07-25-2012, 10:36 AM
|
#2
|
Member
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292
Rep:
|
It can be compared & matched with md5sum fileA & md5sum fileB or diff command
|
|
|
07-25-2012, 10:44 AM
|
#3
|
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281
|
What about order of values, are both files always sorted the same way? For example, what should happen on this:
Quote:
cat File A
20120701,20120702,20120703
cat File B
20120703,20120701,20120702
|
And what about white spaces?
|
|
|
07-25-2012, 04:25 PM
|
#4
|
Member
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147
Rep:
|
Adding to Smilemukul's comment you may also want to check out the comm command in bash it has some nice switches.
|
|
|
07-25-2012, 05:14 PM
|
#5
|
LQ Newbie
Registered: Jul 2012
Location: United Kingdom
Distribution: Ubuntu
Posts: 2
Rep: 
|
The diff command returns zero if the files are the same, or non-zero if they differ.
You can use an if-statement, or just the following single line:
Code:
diff 'File A' 'File B' || exit
|
|
|
All times are GMT -5. The time now is 02:34 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|