RE: Help with sorting


Subject: RE: Help with sorting
jonr@destar.net
Date: Tue Feb 24 2004 - 22:56:28 AKST


This one works like a charm!

> #!/usr/bin/env python
>
> datafile = file('testfile')
> data = datafile.read()
> datafile.close()
>
> map = {}
> lines = [eval(line)[0] for line in data.split('\n') if line]
> for host, foo, index in lines:
> map[int(index)] = host, foo
>
> map = [(k, v, d) for k, (v, d) in map.items()]
> map.sort()
>
> for index, host, foo in map:
> print "('%s', '%s', '%s')" % (host, foo, index, )
>
>
As does this one, though it looks a lot like heiroglyphics. :)

 sed "s/[',()]//g" test | sort -n -k 3 | sed "s/\([^ ]*\)/'\1',/g" | sed
's/^\(.*\),$/(\1),/'

Thanks Arthur and Troy, I had worked all night and am about ready to go
and do it again tonight. I was trying to stay up and see the end result
that the two of you came up with but like a man with no arms, I just
couldn't hang. :)

Both soulutions do exactly what I needed, I really need to learn how to do
some of that there programming and script writing. Do you guys have any
"easy" websites that could help me understand it? I can string commands
together but nothing fancy, nothing quite like the magic performed here
today.

Jon

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Tue Feb 24 2004 - 22:45:48 AKST