in reply to Re: sortmd5 script
in thread sortmd5 script

Thanks talexb for the feedback. I was on holidays for the last two weeks so I'm just answering now.

I think I should explain the task of the script again:
I'm using a lot of MD5 checksum files (md5sums), which hold MD5/file name pairs, for comparison and also for my CD/DVD data backups to verify if they got burned correctly. I also update md5sums files from time to time (see my script addmd5). For several different reasons I like to have these files (i.e. the content of the files) sorted alphabetically after the filename, not the MD5 sum. Therefore a simple sort doesn't work.

The sortmd5 script takes a md5sums file, splits MD5 sums and file names and sorts them after the file names, then joins the lines again and outputs the result.

The default is to work in-place (similar to the -i switch), i.e. write the result back to the original file, if no output file name is given. If the input file had unreadable lines a backup is created before it is overwritten.

Usage example:
The following input MD5 file

443..29D test.avi 563..D93 xyz AB2..FFE a.file
is rewritten to:
AB2..FFE a.file 443..29D test.avi 563..D93 xyz

Replies are listed 'Best First'.
Re^3: sortmd5 script
by talexb (Chancellor) on Aug 28, 2008 at 14:54 UTC

    I would just do a one-liner ..

    alex@foo:~/tmp$ cat >data.in 443..29D test.avi 563..D93 xyz AB2..FFE a.file alex@foo:~/tmp$ perl -e 'while(<>){chomp;($md5,$file)=split;$data{$fil +e}=$md5;}foreach(sort keys %data){print"$data{$_} $_\n";}' <data.in AB2..FFE a.file 443..29D test.avi 563..D93 xyz
    .. and re-direct to an output file as necessary.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds