[lug] Random access from the shell
Jeffrey Haemer
jeffrey.haemer at gmail.com
Thu Nov 13 09:15:17 MST 2008
Sean's being terse. To elaborate: The shell solution only works within a
line. Read stops at line boundaries; it's a shell so its commands are,
unsurprisingly, line-oriented. :-)
If you really want to do arbitrary seeks and random-access I/O in textfiles,
you need to be "more cleverer," like Sean.
Yes, you could also do it by preprocessing the file to replace newlines with
bizarre control characters, then post-process them back. The shell is
Turing compatible. "Use," says Mr. Natural, "the right tool for the job!"
On Wed, Nov 12, 2008 at 5:55 PM, Sean Reifschneider <jafo at tummy.com> wrote:
> Jeffrey Haemer wrote:
> > ## now, an example
> > echo hello, world > foo # a test file to overwrite
> > seek foo 7
> > write "Jeff!"
> > seek foo 0
> > write "Howdy"
>
> That's a cute recipe, but I think I'd use dd to do something like that:
>
> guin:/tmp$ echo 'hello world' >foo
> guin:/tmp$ printf 'Sean!' | dd conv=notrunc of=foo bs=1 seek=6
> 5+0 records in
> 5+0 records out
> 5 bytes (5 B) copied, 8.3809e-05 s, 59.7 kB/s
> guin:/tmp$ printf Howdy | dd conv=notrunc of=foo bs=1 seek=0
> 5+0 records in
> 5+0 records out
> 5 bytes (5 B) copied, 8.2413e-05 s, 60.7 kB/s
> guin:/tmp$ cat foo
> Howdy Sean!
>
> Sean
> --
> Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
> tummy.com, ltd. - Linux Consulting since 1995: Ask me about High
> Availability
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>
--
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell]
http://goyishekop.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20081113/411c168c/attachment.html>
More information about the LUG
mailing list