[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DOS/vfat unerase



On Mon, Jan 12, 2004 at 11:32:14PM -0600, Steven Pritchard wrote:
> perl -e \
> '$/="\xff\xd8";while(<>){open JPG,">".++$n.".jpg" or die "$!";print JPG $/.$_;}'

So since I'm sure this will come up for me eventually, here's a
slightly-more-than-one-liner that actually works:

perl -MFileHandle -e \
 '$/="\xff\xd8"; while (<>) { if (/^....(?:Exif|JFIF)/) { $fh=new FileHandle
  ">".++$n.".jpg" or die "$!";} if (defined($fh)) { print $fh
  $/.substr($_,0,-2); } }'

Or, if you prefer something more readable:

#!/usr/bin/perl

$/="\xff\xd8";
while (<>) {
    if (/^....(?:Exif|JFIF)/) {
        $fh=new FileHandle ">".++$n.".jpg" or die "$!";
    }
    if (defined($fh)) {
        print $fh $/.substr($_,0,-2);
    }
}

NOTE: That will just start creating files named 1.jpg and so on in the
current directory.  Make sure you don't care about the contents of
anything in the directory before running that.  :-)

Steve
-- 
steve@silug.org           | Southern Illinois Linux Users Group
(618)398-7360             | See web site for meeting details.
Steven Pritchard          | http://www.silug.org/

-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.