The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 06-21-2005
pixelbeat pixelbeat is offline
Registered User
  
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
Here's some python for ya:


Code:
#!/usr/bin/env python
                                                                                                          
import sys
                                                                                                          
groups={}
                                                                                                          
while 1:
     line = sys.stdin.readline()
     if line == '':
         break
     try:
         key,value=line.strip().split()
         if not groups.has_key(key):
            groups[key]=[value]
         else:
            groups[key].append(value)
     except:
         pass
                                                                                                          
keys=groups.keys()
keys.sort()
for key in keys:
    print key,
    print ",".join(groups[key])