[ale] Binary Grep
Joe Steele
joe at madewell.com
Wed Nov 17 18:01:01 EST 2004
On Wednesday, November 17, 2004 1:34 PM, Fletch wrote:
>
> $ perl -le 'print "a" x 2040, "\xff" x 16, "b" x 512' > foo
> $ perl -lne 'BEGIN{$/=\1024}$o=($.-1)*1024-length$b;$b.=$_;print "hit byte ", $o + $-[0] if $b =~ /\xff{16}/;$b=substr($b,-15,15)' foo
> hit byte 2040
>
Well, since I've already been labeled a spoil sport... :)
What about:
$ perl -le 'print "a" x 400, "\xff" x 16, "a" x 400, "\xff" x 16, "a" x 400, "\xff" x 16' > foo
$ perl -lne 'BEGIN{$/=\1024}$o=($.-1)*1024-length$b;$b.=$_;print "hit byte ", $o + $-[0] if $b =~ /\xff{16}/;$b=substr($b,-15,15)' foo
hit byte 400
hit byte 1232
^^^^^^^^^ No hit byte at 816 :(
Trying again:
$ perl -le 'print "a" x 400, "\xff" x 16, "a" x 400, "\xff" x 16, "a" x 400, "\xff" x 16' > foo
$ perl -lne 'BEGIN{$/=\31}$o=($.-1)*31-length$b;$b.=$_;print"hit byte ",$o+$-[0]if$b=~/\xff{16}/;$b=substr($b,-15,15)' foo
hit byte 400
hit byte 816
hit byte 1232
Notice also that I have cut down on the gratuitous use of needless
white space without any loss of readability :)
--Joe
More information about the Ale
mailing list