Solved

Linux, difference between configuration files

Posted on 2014-11-20
3
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

710 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