Merging Related Information from 2 Tables

Giorgos Keramidas keramida at ceid.upatras.gr
Thu Oct 29 21:49:26 UTC 2009


On Thu, 29 Oct 2009 18:37:09 +0200, Giorgos Keramidas <keramida at ceid.upatras.gr> wrote:
> You should use a Perl or Python script, and a hash...
> ...
> Running this script should produce something like:
>
> : keramida at 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 at 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 at 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 at kobe:/home/keramida$ python hello.py
: 127.0.0.1            kobe                           "This is a test"
: 127.0.0.1            localhost
: keramida at kobe:/home/keramida$

Add or remove formatting as you see fit :-)



More information about the freebsd-questions mailing list