Solved

Linux, difference between configuration files

Posted on 2014-11-20
3
175 Views
Last Modified: 2014-11-20
On Red Hat 6.x, I need a tool that will tell me the difference between 2 configuration files

Is there a tool that will do that

Also , is there a tool that will approach this in a more complex manner, and will NOT report all lines after the first mismatch, but will only report lines in the first file that are not contained in the second file ?  For Instance:

a.conf

Line 1
Line 2
Line 3
line 4
line 5
line  6

Open in new window


and b.conf

Line 1
Line 2
line 4
line 5
line  6

Open in new window


is there a tool that will report the difference as :

Line 3

Open in new window


instead of

Line 3
line 4
line 5
line  6

Open in new window


Thanks
0
Comment
Question by:Anthony Lucia
  • 2
3 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40455407
The first tool yu're looking for is "diff".

The second tool you're looking for is "comm":

comm -2 -3 a.conf b.conf

comm creates 3 reports (in 3 columns):
1. Lines only in file 1
2 Lines only in file 2
3. Lines common to file 1 and file 2

The options "-1" "-2" and "-3" suppress displaying the respective column.
0
 
LVL 21

Expert Comment

by:Mazdajai
ID: 40455409
Try diff

diff a.conf b.conf

Open in new window

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40455446
Note: Please be aware that the files to compare must be sorted to create reliable results!
Your files are sorted, that's why it works in your case.

With non-sorted files, if you don't want to touch the originals, you can create sorted temporary versions and compare these.

"comm" accepts standard input for one of the input files, so only one of them must be sorted into a file.

sort b.conf > b.conf.sorted
sort a.conf | comm -2 -3 - b.conf.sorted

Note the dash (-) as the first file parameter. It means: "read from stdin".
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now