Re: seek within a large file
From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: Fri, 17 Oct 2003 06:29:07 GMT
On Fri, 17 Oct 2003 06:50:47 +0100, Andy Baxter <email@example.com> wrote:
> On Fri, 17 Oct 2003 04:59:07 +0000, Alan Connor wrote:
>> On Fri, 17 Oct 2003 04:48:29 +0100, Andy Baxter <firstname.lastname@example.org> wrote:
>>>> I can't help but point out that while he is following your advice,
>>>> he could already have read the file.
>>>> I'd probably cut it into pieces first with split, deleting the original
>>>> file, then cat it back together afterwards.
>>>> You can do whatever way you want, but it would be cool if you would actually
>>>> post a *practical* approach to doing what he wants, rather than just some
>>>> vague geek-talk....
>>> If he only wanted to do this once from the command line, your solution
>>> might work but would be very inefficient. It would probably be
>>> better to do something like:
>>> dd if=bigfile of=samplefile bs=1024 skip=1048576 count=samplesize
>> That's IT! I *knew* there was a quick way to do that right, without writing
>> a new utility.
>>> But from reading the original question, I don't think that's what he was
>>> looking for - sounds more like he's writing a program which needs to be
>>> run more than once and hence should be reasonably efficient.
>> And is yours not? Seems like using it in a script with read to get the
>> variables would work nicely.
>> Is there, Andy, a utility that converts kb decimal to kb binary? Or just
>> any number to whatever its not in at present, hex/octal/dec?
> Have a look at man printf and man 3 printf.
> You can convert (unsigned) decimal to octal with
> printf '%o' decimal-number
didn't get anything but printf '' 20
when I tried that with 20
> printf doesn't do binary, but you could convert octal to binary in a shell
> script using some kind of look up table - e.g. a file like:
> 0 000
> 1 001
> 2 010
> 3 011
> 4 100
> 5 101
> 6 110
> 7 111
> remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
> bin unless notified with [html] or [attachment] in the subject line.
So where did you get skip=1048576 then? How did you convert 1GB to that?
The way I get them when it seems like a script needs the 'binary-kb', is
to copy a file that's close to that size, add and subtract lines until
ls -sh reads, say, 16mb, and then run just ls -l on it .... Sure seems
like the long way around the barn....
-- Alan C