LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-24-2007, 05:11 AM   #1
samyboy
LQ Newbie
 
Registered: Nov 2006
Posts: 12

Rep: Reputation: 0
diff command on a config file


Hello,

I'm trying to alias the diff command to compare two config files (samba, apache, etc).
That means that white lines and commented lines will be ignored.

Unfortunately I'm having trouble creating the regexp to match commented lines.
Here's my command :

diff -BbwEiy --suppress-common-lines -I '^[[:space:]]*#'

'^[[:space:]]*#' means clearly : at the beginning of the line, zero or more spaces then a # character (where "spaces" could be tabs as well).

I'm not a regexp expert but mine looks right.
 
Old 01-24-2007, 10:15 PM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I haven't checked your diff options, but I don't see a problem with your regexp. I am wondering if your problem could bethe quoting used in connection with your alias command. Could you post the whole alias command?
 
Old 01-25-2007, 04:53 AM   #3
samyboy
LQ Newbie
 
Registered: Nov 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Actually, since the command does not work yet I only work on the command line without alias.

Anyway, here's how I plan to do it:

alias diffconfig="diff -BbwEiy --suppress-common-lines -I '^[[:space:]]*#'"

I try to avoid quoting problems with using the simple quotes once and the double quotes once.
 
Old 01-25-2007, 05:11 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,265

Rep: Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027
Well, I tried your regex on a simple diff, and it worked fine.
This was on a standard Ubuntu Dapper build.
 
Old 01-25-2007, 06:50 AM   #5
samyboy
LQ Newbie
 
Registered: Nov 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Hi,

ok use 2 similar files except 2 different lines. In one file, insert a new line just before the different line.

Something like:
a
b


and

a

c


It should output that b!=c but the blank line is in the result.

I think the diff utility is not made to compare instructions of config files.
 
Old 01-26-2007, 01:14 AM   #6
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
samyboy,

after playing around with your example and some similar simple files, I have to admit to not understanding how any of the diff options that are supposed to suppress lines work.

syg00,

My lack of understanding extends to the test you did. Could you post your test files, command used and output please? I would think what samyboy wants to do should be doable, but I appear to missing something fundamental.
 
Old 01-26-2007, 04:01 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,265

Rep: Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027
I simply took the Ubuntu /boot/grub/menu.lst and created a copy which I played around with. Being Debian based, it is full of comments - and blank lines. My response above was based on simply editting some of the comments, and I missed the reference to blank lines.
I actually modified the regex to handle blank lines (using egrep as a test).
<edit> wasn't for the diff, just to see if egrep would do it </edit>

Later testing seemed to confirm (somewhat) what samyboy is saying. I tried his last post, and it worked fine if new lines were (only) newlines.
An inserted line (especially as first line in the member) that had a "space" character in addition to the newline replicated samyboys problem.

Can't explain it ...

Last edited by syg00; 01-26-2007 at 04:03 AM.
 
Old 01-26-2007, 06:00 AM   #8
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by syg00
Later testing seemed to confirm (somewhat) what samyboy is saying. I tried his last post, and it worked fine if new lines were (only) newlines.
An inserted line (especially as first line in the member) that had a "space" character in addition to the newline replicated samyboys problem.
I was playing around with various variations of the trivial files samyboy suggested. Even with a completely empty line (verified with cat -E testfile) I couldn't get the -B and --ignore-blank-lines options to do anything. I also tried the -I option with the following regexps:

"^$"
"^[[:space:]]*$"
"^[[:space:]]*#?"

and probably some others. I tried this on Ubuntu edgy eft and an archaic RH system. I couldn't get anything to work so I figure I must be missing something basic. Like I said, I couldn't even get it to work with two sucessive newlines where you report success.

When I get a chance I'll try to play around with Ubuntu's menu.lst to see if I can replicate your results. I've used regular expressions in other contexts, but this is the first time I've tried anything fancy with diff.
 
Old 01-31-2007, 02:44 AM   #9
samyboy
LQ Newbie
 
Registered: Nov 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Hi there,

I'm quite surprized how my post grown since the last time I logged in.

I want to be sure that I want to handle to things:
  • we don't care about blank lines
  • we don't care about comments

Here's the problem I'm dealing with :

[09:37:03] sam@asumsk:tmp $ cat a
a
b
c
[09:37:05] sam@asumsk:tmp $ cat b
a
b
c

d
[09:37:06] sam@asumsk:tmp $ diff -BbwEiy --suppress-common-lines -I '^[[:space:]]*#' a b
>
> d


This makes the jobs because if the config is identical the command works.
But if the config diffeers the output should not contain the white line (because we just don't care about white lines).

I think I should head another way and use a script.

Last edited by samyboy; 01-31-2007 at 02:50 AM.
 
  


Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply diff to a file powah Linux - Newbie 1 03-07-2006 02:00 PM
help on diff command anandss2004 Programming 2 11-01-2005 12:58 PM
What is *.diff file? carboncopy Slackware 1 05-19-2004 10:26 AM
DIFF (or other file comparison) ciscokid1967 Linux - General 1 12-11-2003 02:13 PM
the diff command or any other similar things murshed Linux - Newbie 4 02-12-2003 10:07 PM


All times are GMT -5. The time now is 08:42 PM.

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