Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linux, difference between configuration files

Posted on 2014-11-20
3
Medium Priority
?
183 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

886 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