From: Robert Klemme Date: 2009-11-29T01:05:06+09:00 Subject: Re: Ruby byte access to disk sectors like dd does On 11/28/2009 01:26 AM, Bill Kelly wrote: >> The more fun solution would of course be to code the hex dumping in >> Ruby also. :-) > > :) Here's a stab at it... (it does work properly if the last > read returns fewer than 16 bytes.) What makes it stop working properly if the file size is a multiple of 16? > ruby -e 'File.open("/dev/hdb", "rb") {|io| print(io.read(512))}' | > ruby -e 'i=0; while(x=ARGF.read(16)); puts("%08x %-32s %s" % [i, x.unpack("H*"), x.tr("^\040-\176",".")]); i+=16; end' Why do you separate this in two processes? I've munged it a bit... ruby -e 'File.open("/dev/hdb", "rb"){|io|i=0;while(l=io.read(16)); printf("%06x %-32s %s\n",i,l.unpack("H*").first,l.tr("^\040-\176",".")); i+=l.bytesize end}' Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/