[ale] Binary Grep
Greg Freemyer
greg.freemyer at gmail.com
Wed Nov 17 12:33:06 EST 2004
On Wed, 17 Nov 2004 12:03:49 -0500, Joe Steele <joe at madewell.com> wrote:
> On Tuesday, November 16, 2004 9:32 PM, Fletch wrote:
> >
> > $ perl -le 'print "a" x 2048, "b" x 512, "\xff" x 16, "b" x 512' > foo
> > $ perl -lne 'BEGIN{$/=\1024} print "hit byte ", ($.-1) * 1024 + $-[0] if /\xff{16}/' foo
> > hit byte 2560
> > $ perl -le 'print "a" x 2048, "b" x 1512, "\xff" x 16, "b" x 512' > foo
> > $ perl -lne 'BEGIN{$/=\1024} print "hit byte ", ($.-1) * 1024 + $-[0] if /\xff{16}/' foo
> > hit byte 3560
> >
>
> But what about:
>
> $ perl -le 'print "a" x 2047, "\xff" x 16, "b" x 512' > foo
> $ perl -lne 'BEGIN{$/=\1024} print "hit byte ", ($.-1) * 1024 + $-[0] if /\xff{16}/' foo
> $
>
> ^^^^^^ No hit byte found :(
>
Spoil Sport :(
I was so impressed with Perl and Fletch that it could do this in a single line.
I don't speak Perl at all, so I did not realize he was only scanning
1K blocks and any patterns that crossed the boundary were ignored. (I
assume that is the issue you found.)
To be honest, the biggest surprise for me is that there apparently is
not a stardard tool for doing this.
Fortunately Fletch's method was good enough to solve my immediate
need. I might experiment with your lex code, but I truly don't
understand lex. Perl I at least have a chance of understanding.
Thanks
Greg
--
Greg Freemyer
More information about the Ale
mailing list