> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Madhur
> Sent: Friday, January 18, 2008 4:23 AM
> To: python-list@python.org
> Subject: Filtering two files with uncommon column
> 
> 
> Basically I want to compare the two files based on second column. If
> the second
> column matches on both the files do not print anything, else if there
> is no matc
> h in for the second column for first file in second file then print it
> under Fil
> e1 header, else if there is no match for the second column for second
> file in fi
> rst file print it under File2 header.
> 


I often do this to compare property files between environments.  The
follow algorithm works for any number of files by creating a dictionary
of lists (or hash of arrays in Perl-ese.)

Create a dictionary
Index = -1
For file in files
        Index++
        For line in file
                col = match/split/regex the column
                If col not in dictionary
                        Dictionary[col] = []

                extend dictionary[col] to length of index
                dictionary[col][index] = col

for col in sort(dictionary.keys()):
        extend dictionary[col] to length of index
        print dictionary[col]   




*****

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA622


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to