Re: [ast-users] Edit 10GB file with fixed size records

2013-07-26 Thread Janis Papanagnou
  Does ksh have an API to edit a file at a specific position pos1, read
  n1 bytes, and write n1 bytes at that position without truncating the
  file? I need this to do edit a file in place without reading and
  writing it completely each time.
 
  Yes, ksh has seek redirection operators.
 
[snip]
 
 
  read -N $n1 content 0$f #((pos1))
  printf %s $(fun $content) 1$f #((pos1))
 

[snip]
 
 How would this example look like if I opened a file descriptor with
 the number 19? ksh seems to use file descriptors 0-9 for manual usage,
 but descriptors opened with exec {filed}name.rec use numbers  10.

I'd have thought by prepending {filed} to the seek redirections;
  {filed}#((pos1))  and  {filed}#((pos1))  respectively.
Doesn't that work?

Janis

 
 Tina
 -- 
 Tina Harriott  - Women in Mathematics
 Contact: tina.harriott.mathemat...@gmail.com
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Edit 10GB file with fixed size records

2013-07-25 Thread Tina Harriott
On 24 July 2013 22:57, Janis Papanagnou janis_papanag...@hotmail.com wrote:
 Does ksh have an API to edit a file at a specific position pos1, read
 n1 bytes, and write n1 bytes at that position without truncating the
 file? I need this to do edit a file in place without reading and
 writing it completely each time.

 Yes, ksh has seek redirection operators.

 Here's an ad hoc example (not sure whether the features are
 applied proficiently, but it seems to work :-)

 f=somefile

 cat EOT $f
 Hello world!
 My good friend.
 How are you?
 EOT

 function fun  ## palindrome (just for example)
 {
   arg=$1 x=
   (( len=${#arg} ))
   for ((i=0; ilen; i++))
   do  res=${arg:i:1}$res
   done
   printf %s $res
 }

 pos1=18
 n1=8

 read -N $n1 content 0$f #((pos1))
 printf %s $(fun $content) 1$f #((pos1))


 Outputs:

 Hello world!
 My goneirf dod.
 How are you?


 Hope it's of some use to you.

How would this example look like if I opened a file descriptor with
the number 19? ksh seems to use file descriptors 0-9 for manual usage,
but descriptors opened with exec {filed}name.rec use numbers  10.

Tina
-- 
Tina Harriott  - Women in Mathematics
Contact: tina.harriott.mathemat...@gmail.com
___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users