473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using python to parse md5sum list

Hi

I'm new to programming and i'd like to write a program that will parse
a list produced by md5summer and give me a report in a text file on
which md5 sums appear more than once and where they are located.

the end end goal is to have a way of finding duplicate files that are
scattered across a lan of 4 windows computers.

I've dabbled with different languages over the years and i think
python is a good language for this but i have had a lot of trouble
sifting through manual and tutorials finding out with commands i need
and their syntax.

Can someone please help me?

Thanks.

Ben
Jul 18 '05 #1
4 2880
Among many other things:

First, you might want to look at os.path.walk()
Second, look at the string data type.

Third, get the Python essential reference.

Also, Programming Python (O'Riely) actually has a lot in it about stuff like
this. Its a tedious read, but in the end will help a lot for administrative
stuff like you are doing here.

So, with the understanding that you will look at these references, I will
foolishly save you a little time...

If you are using md5sum, tou can grab the md5 and the filename like such:

myfile = open(filename)
md5sums = []
for aline in myfile.readlines():
md5sums.append(aline[:-1].split(" ",1))
myfile.close()

The md5 sum will be in the 0 element of each tuple in the md5sums list, and
the path to the file will be in the 1 element.
James

On Saturday 05 March 2005 07:54 pm, Ben Rf wrote:
Hi

I'm new to programming and i'd like to write a program that will parse
a list produced by md5summer and give me a report in a text file on
which md5 sums appear more than once and where they are located.

the end end goal is to have a way of finding duplicate files that are
scattered across a lan of 4 windows computers.

I've dabbled with different languages over the years and i think
python is a good language for this but i have had a lot of trouble
sifting through manual and tutorials finding out with commands i need
and their syntax.

Can someone please help me?

Thanks.

Ben


--
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
Jul 18 '05 #2
Ben Rf wrote:
I'm new to programming and i'd like to write a program that will parse
a list produced by md5summer and give me a report in a text file on
which md5 sums appear more than once and where they are located.


This should do the trick:

"""
import fileinput

md5s = {}
for line in fileinput.input():
md5, filename = line.rstrip().split()
md5s.setdefault(md5, []).append(filename)

for md5, filenames in md5s.iteritems():
if len(filenames) > 1:
print "\t".join(filenames)
"""

Put this in md5dups.py and you can then use
md5dups.py [FILE]... to find duplicates in any of the files you
specify. They'll then be printed out as a tab-delimited list.

Key things you might want to look up to understand this:

* the dict datatype
* dict.setdefault()
* dict.iteritems()
* the fileinput module
--
Michael Hoffman
Jul 18 '05 #3
In <ma***************************************@python. org>, James Stroud
wrote:
If you are using md5sum, tou can grab the md5 and the filename like such:

myfile = open(filename)
md5sums = []
for aline in myfile.readlines():
md5sums.append(aline[:-1].split(" ",1))
md5sums.append(aline[:-1].split(None, 1))

That works too if md5sum opened the files in binary mode which is the
default on Windows. The filename is prefixed with a '*' then, leaving
just one space between checksum and filename.
myfile.close()


Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '05 #4
On 5 Mar 2005 19:54:34 -0800, rumours say that be********@gmail.com (Ben Rf)
might have written:

[snip]
the end end goal is to have a way of finding duplicate files that are
scattered across a lan of 4 windows computers.


Just in case you want to go directly to that goal, check this:

http://groups-beta.google.com/group/...8e292ec9adb82d

It doesn't read a file at all, unless there is a need to do that. For example,
if you have ten small files and one large one, the large one will not be read
(since no other files would be found with the same size).

In your case, you can use the find_duplicate_files function with arguments like:
r"\\COMPUTER1\SHARE1", r"\\COMPUTER2\SHARE2" etc
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Timothy Martens | last post by:
When I run the Python-2.3.exe on my WIN2K box and go through the initial dialogues, the installer frezes at 1% when it's "Copying File C:\Python23\UNWISE.exe" Any ideas ANYONE? tim.
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
5
by: jwb | last post by:
Hello all, I just was wondering if any one knows how to compare compiled VB.NET executables to determine whether or not they are identical. In the dark ages (read: pre-CLR and .NET) one could...
3
by: Gary Townsend | last post by:
Hey all i am looking to see if anyone has created a function or knows how to create an md5sum that would match the md5sum routines found commonly in C++ and Linux. Gary Townsend
9
by: ursache.marius | last post by:
Hi I noticed that the md5 computed with md5 module from python is different then the md5 sum computed with md5sum utility (on slackware and gentoo). i.e. $echo marius|md5sum...
5
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
0
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by...
4
by: Udai Kiran | last post by:
Hi all, I have been looking for a c function that can calculate md5sum of file given the path of the file. I know that the md5sum utility is included in gnu coreutils. but how can I use this as a...
3
by: Alexnb | last post by:
Okay, I tried to follow that, and it is kinda hard. But since you obviously know what you are doing, where did you learn this? Or where can I learn this? Maric Michaud wrote:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.