From owner-freebsd-questions@FreeBSD.ORG Thu Oct 29 21:49:26 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 C0F9F106568B for ; Thu, 29 Oct 2009 21:49:26 +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 28AF68FC13 for ; Thu, 29 Oct 2009 21:49:26 +0000 (UTC) Received: from mail.ceid.upatras.gr (unknown [10.1.0.143]) by poseidon.ceid.upatras.gr (Postfix) with ESMTP id 0F3ADEB474C; Thu, 29 Oct 2009 23:49:24 +0200 (EET) Received: from localhost (europa.ceid.upatras.gr [127.0.0.1]) by mail.ceid.upatras.gr (Postfix) with ESMTP id EFCB5451B2; Thu, 29 Oct 2009 23:49:23 +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 pYuG3v5reFKI; Thu, 29 Oct 2009 23:49:23 +0200 (EET) Received: from kobe.laptop (ppp-94-64-196-111.home.otenet.gr [94.64.196.111]) by mail.ceid.upatras.gr (Postfix) with ESMTP id A6AB545152; Thu, 29 Oct 2009 23:49:23 +0200 (EET) Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id n9TLnMCk082042 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Oct 2009 23:49:23 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id n9TLnMZB082041; Thu, 29 Oct 2009 23:49:22 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Martin McCormick References: <200910291539.n9TFcuKB078966@dc.cis.okstate.edu> <873a529mx6.fsf@kobe.laptop> Date: Thu, 29 Oct 2009 23:49:22 +0200 In-Reply-To: <873a529mx6.fsf@kobe.laptop> (Giorgos Keramidas's message of "Thu, 29 Oct 2009 18:37:09 +0200") Message-ID: <87ws2d27ml.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 21:49:26 -0000 On Thu, 29 Oct 2009 18:37:09 +0200, Giorgos Keramidas wrote: > You should use a Perl or Python script, and a hash... > ... > 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. On Thu, 29 Oct 2009 13:44:12 -0500, Martin McCormick wrote: > Perl and python-- I wasn't even thinking of that! Thank you. I have > installed python now on the FreeBSD system and will start learning it. > > A records look like: > > hydrogen.cis.osu. 43200 IN A 192.168.2.123 > > Text or TXT records look similar except that the data they > convey are ASCII text strings of various information that are > either read by people or maybe tell servers how to behave toward > that particular client. > > hydrogen.cis.osu. 5 IN TXT "cordell-north,009,192.168.2.123" Once you slurp all the A and TXT records in a hash-map or another data structure of your own with Python, you can iterate over the hash and print parts or all of it. For example, if you have the hash I printed in my previous reply, you can print all addresses and text records with a small bit of code: : keramida@kobe:/home/keramida$ cat hello.py : #!/usr/bin/env python : : hosts = {'kobe': [('A', '127.0.0.1'), : ('TXT', '"This is a test"')], : 'localhost': [('A', '127.0.0.1')]} : : for h in sorted(hosts): : addrs = [x[1] for x in hosts[h] if x[0] == 'A'] : txts = [x[1] for x in hosts[h] if x[0] == 'TXT'] : for a in addrs: : if len(txts) == 0: : txts = [""] : for t in txts: : print "%-20s %-30s %s" % (a, h, t) : keramida@kobe:/home/keramida$ python hello.py : 127.0.0.1 kobe "This is a test" : 127.0.0.1 localhost : keramida@kobe:/home/keramida$ Add or remove formatting as you see fit :-)