Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Oct 2009 23:49:22 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Martin McCormick <martin@dc.cis.okstate.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Merging Related Information from 2 Tables
Message-ID:  <87ws2d27ml.fsf@kobe.laptop>
In-Reply-To: <873a529mx6.fsf@kobe.laptop> (Giorgos Keramidas's message of "Thu, 29 Oct 2009 18:37:09 %2B0200")
References:  <200910291539.n9TFcuKB078966@dc.cis.okstate.edu> <873a529mx6.fsf@kobe.laptop>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 29 Oct 2009 18:37:09 +0200, Giorgos Keramidas <keramida@ceid.upatras.gr> 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 <martin@dc.cis.okstate.edu> 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 :-)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87ws2d27ml.fsf>