LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2007, 06:11 PM   #1
reaky
Member
 
Registered: Oct 2003
Posts: 60

Rep: Reputation: 15
plz help me to compare


Dear all
I want to compare the zones in both my Linux Bind servers, So I greped the first line of all of them with
#> grep 'zone "' named.conf > named.1
and the same for named.conf 2
now I get two files named.1 named.2, with the following syntax
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
etc..

First Can any one tell me a grep command to just get the domains name between the "" in a file
second I want to compare between the both files and get the domains that in named.1 and not found in named.2
 
Old 05-03-2007, 07:09 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Not tested:

Code:
egrep -o '"[^"]+"' file1 | sed 's/"//g'  > comp1
egrep -o '"[^"]+"' file2 | sed 's/"//g' > comp2
sdiff -s comp1 comp2

Cheers,
Tink
 
Old 05-03-2007, 07:46 PM   #3
reaky
Member
 
Registered: Oct 2003
Posts: 60

Original Poster
Rep: Reputation: 15
Thanx so much
the first command worked perfectly
But there's something in the second one
It compared with two files as they are arranged like each others, But they don't
For example name1
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
etc..

But named2
zone "domain5.tv" in {
zone "domain3.cc" in {
zone "domain2.com" in {
zone "domain4.net" in {
zone "domain1.com" in {
etc..

I just want it to get the domains that are in one of them and not in the other, To add it to the other one, Got it.

Thanx for your help.
 
Old 05-03-2007, 09:40 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by reaky
I just want it to get the domains that are in one of them and not in the other, To add it to the other one, Got it.
how about:
Code:
$ cat name1 name2 |sort |uniq > allnames
$ cat allnames
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
Of course, if the original order is important to you this might not be so great...
 
Old 05-03-2007, 10:39 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
egrep -o '"[^"]+"' file1 | sed 's/"//g' | sort  > comp1
egrep -o '"[^"]+"' file2 | sed 's/"//g' | sort  > comp2
sdiff -s --left-column comp1 comp2
sdiff -s --left-column comp2 comp1
How's that?


Cheers,
Tink
 
Old 05-03-2007, 10:57 PM   #6
reaky
Member
 
Registered: Oct 2003
Posts: 60

Original Poster
Rep: Reputation: 15
No I don't want to arrange them, I just want to compare.
Thanx for help
 
Old 05-04-2007, 12:27 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I recently had to prepare scripts that extracted the names of mpeg files in several video devices against one of the devices. I used the "comm" command to find entries in one list that were unique, and then used that list as a grep pattern file to the original.
Code:
$ cat rdytospot
#!/bin/bash
for file in *.RDY; do
   sed -e '0,/Unmanaged/d' -e '/NETTEST/d' -e '/^$/,$d' -e '/^$/d' -e 's/\(.*MPG\).*/\1/' -e 's/[[:blank:]]//g' "$file"
done > unmanagedspots
sort -u unmanagedspots >unmsorted
comm -23 unmsorted solicitorlist >deletelist
if grep -f deletelist solicitorlist; then
   echo Error!  The delete list contains files in the solicitor
   exit 1
fi
sed 's/^/del /' deletelist >clean.dvc
rm unmanagedspots unmsorted deletelist
You could do something similar:
Code:
sed -n '/^zone/s/^[^"]*"\([^"]*\)".*/\1/p' named2 | sort >named2list
sed -n '/^zone/s/^[^"]*"\([^"]*\)".*/\1/p' named1 | sort >named1list
comm -13 named1list named2list >UniqInNamed2
grep -f UniqInNamed2 named2
By the way, your two samples have exactly the same domain names, just in a different order.
Using different samples:
$ cat named1
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {

$ cat named2
zone "domain8.tv" in {
zone "domain3.cc" in {
zone "domain7.com" in {
zone "domain4.net" in {
zone "domain1.com" in {

$ grep -f UniqInNamed2 named2
zone "domain8.tv" in {
zone "domain7.com" in {

Last edited by jschiwal; 05-04-2007 at 12:31 AM.
 
Old 05-04-2007, 01:53 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by reaky
No I don't want to arrange them, I just want to compare.
Thanx for help
Sorry mate, w/o sorting the diff output will be
garbage. With the sorting you get two sets that
(most likely) won't appear in either, and then
you could feed them back. If that's not what
you're after *I* can't help you.



Cheers,
Tink
 
Old 05-04-2007, 10:59 AM   #9
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
try this:
Code:
# system 1
grep '^zone "' named.conf | awk '{print $2}' | tr -s '"' ' ' > file1
# system 2
grep '^zone "' named.conf | awk '{print $2}' | tr -s '"' ' ' > file2
awk ' FILENAME=="file1" { arr[$0]=1}
      FILENAME=="file2" {
           if( !arr[$0]) { print $0 }
      }
    ' file1 file2
 
Old 05-04-2007, 01:01 PM   #10
reaky
Member
 
Registered: Oct 2003
Posts: 60

Original Poster
Rep: Reputation: 15
Dear all
Thanx so much ,You really helped me so much
THax all again.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to compare munna_dude Programming 10 03-21-2007 07:50 AM
Compare two files namit Linux - Software 1 12-31-2005 08:10 AM
plz plz help me regarding route mapping nedian123 Programming 1 07-13-2004 08:17 AM
plz plz solve my route mapping problem nedian123 Linux - Networking 1 07-12-2004 09:41 PM
redhat problems plz plz help sap666 Linux - Newbie 5 07-30-2003 10:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:43 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration