From owner-freebsd-questions@FreeBSD.ORG Thu Oct 29 16:37:12 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDC8E106566C for ; Thu, 29 Oct 2009 16:37:12 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from poseidon.ceid.upatras.gr (poseidon.ceid.upatras.gr [150.140.141.169]) by mx1.freebsd.org (Postfix) with ESMTP id 2C6318FC1A for ; Thu, 29 Oct 2009 16:37:11 +0000 (UTC) Received: from mail.ceid.upatras.gr (unknown [10.1.0.143]) by poseidon.ceid.upatras.gr (Postfix) with ESMTP id 1E1C2EB472F; Thu, 29 Oct 2009 18:37:11 +0200 (EET) Received: from localhost (europa.ceid.upatras.gr [127.0.0.1]) by mail.ceid.upatras.gr (Postfix) with ESMTP id 0CD19451BC; Thu, 29 Oct 2009 18:37:11 +0200 (EET) X-Virus-Scanned: amavisd-new at ceid.upatras.gr Received: from mail.ceid.upatras.gr ([127.0.0.1]) by localhost (europa.ceid.upatras.gr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jRnwELja0fJd; Thu, 29 Oct 2009 18:37:10 +0200 (EET) Received: from kobe.laptop (ppp-94-64-253-165.home.otenet.gr [94.64.253.165]) by mail.ceid.upatras.gr (Postfix) with ESMTP id ADFBC451B2; Thu, 29 Oct 2009 18:37:10 +0200 (EET) Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id n9TGbA3I085321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Oct 2009 18:37:10 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id n9TGb9Rt085311; Thu, 29 Oct 2009 18:37:09 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Martin McCormick References: <200910291539.n9TFcuKB078966@dc.cis.okstate.edu> Date: Thu, 29 Oct 2009 18:37:09 +0200 In-Reply-To: <200910291539.n9TFcuKB078966@dc.cis.okstate.edu> (Martin McCormick's message of "Thu, 29 Oct 2009 10:38:56 -0500") Message-ID: <873a529mx6.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-questions@freebsd.org Subject: Re: Merging Related Information from 2 Tables X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2009 16:37:12 -0000 On Thu, 29 Oct 2009 10:38:56 -0500, Martin McCormick wrote: > This is probably going to be a hashing exercise but I am checking to see > if any of the building blocks needed are already out there. > > The problem is simple to describe in that there are 2 tables. One is a > DNS zone transfer table of all the A or Address records in a given zone > or from several zones for that matter. the other table is from the same > zones and consists of text or TXT records. The only thing the 2 tables > have in common is that some of the TXT records share the exact same name > field as the A records so we should be able to display the important > contents of the A and TXT records on the same line if their names match. > The challenge is to do this quickly so some sort of hash function is > needed to locate A and TXT records having the same name. Hi Martin, You should use a Perl or Python script, and a hash... If you show us a few sample lines from the input file and how you want the output to look, it shouldn't be too hard to quickly hack one of those together. With a short input file like this: : keramida@kobe:/tmp$ cat input-file : localhost IN A 127.0.0.1 : kobe IN A 127.0.0.1 : kobe IN TXT "This is a test" You can construct a hash map of hostname -> list of records in Python with a relatively short script: : #!/usr/bin/env python : : import re : import sys : : are = None # a regexp for matching 'A' records : txtre = None # a regexp for matching 'TXT' records : : try: : are = re.compile(r'^\s*(\S+)\s+[iI][nN]\s+[aA]\s+(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).*$') : txtre = re.compile(r'^\s*(\S+)\s+[iI][nN]\s+[tT][xX][tT]\s+(.*)$') : except Exception, inst: : sys.stderr.write('regexp error: %s' % str(inst)) : sys.exit(1) : : hosts = {} : : for l in sys.stdin.readlines(): : l = l.rstrip('\n\r') : # Is this an A record? : m = are.match(l) : if m: : (name, addr) = (m.group(1), m.group(2)) : rec = ('A', addr) : if not name in hosts: : hosts[name] = [rec] : else: : hosts[name].append(rec) : # Is this a TXT record? : m = txtre.match(l) : if m: : (name, text) = (m.group(1), m.group(2)) : rec = ('TXT', text) : if not name in hosts: : hosts[name] = [rec] : else: : hosts[name].append(rec) : : print hosts Running this script should produce something like: : keramida@kobe:/tmp$ python martin.py < input-file : {'kobe': [('A', '127.0.0.1'), ('TXT', '"This is a test"')], : 'localhost': [('A', '127.0.0.1')]} When you have the hash map of hostname to record-list for each host, you can select and print any combination of host<=>record from this hash.